Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Linking issues (Dev C++)

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just tossed together two small DLLs and linked them to a project for testing. I included them both, and linked them both, but one of them isn't correctly linked it seems. The one that isn't working(SDL_gfx) gives me the typical '[Linker Error]undefined reference' to any function calls from that dll(SDL_gfx). SDL_gfx is placed correctly in the right files for Dev C++ to use, and I even replaced it several times to be sure. It still gives me linker errors. The problem seems to be with the fact that my SDL_gfx dll uses other dlls that I downloaded. (SDL_ttf and SDL_image) In the linker parameters of the project, I have linked the libraries in multiple orders, and the all seem to cause the same linker errors. I currently am linking them like this: -lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf -SDL_gfx -lSDL_input SDL_input is the other dll I made, and it works fine. It doesn't rely on SDL_image, or SDL_ttf, but only SDL itself. It's SDL_gfx I have issues with. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
Dev C++ uses the GNU compiler collection, GCC. When linking libraries with GCC, order is important: the linker does not go back over previously read libraries to satisfy newly introduced unresolved symbols from later libraries. Your SDL_image may work only because it relies exclusively on resolved symbols at the point it's being encountered.

In other words, you need to put your libraries that depend on, say, libSDL, to the left of that library in the link line. It's okay to have a libvrary appear more than once in a link line, if necessary (although that implies you've got circular dependencies. Directed acyclic graphs are preferrable).

Share this post


Link to post
Share on other sites
Thanks, I was doing it right to left before. Still not working though; I now have it like this:
-SDL_gfx -lSDL_input -lSDL_image -lSDL_ttf -lmingw32 -lSDLmain -lSDL

SDL_gfx is the only one who is giving me problems.

Here is the .h file, is anything wrong with it?

#include <iostream>
#include "SDL\SDL.h"
#include "SDL\SDL_image.h"
#include "SDL\SDL_ttf.h"

#ifndef MAIN_PARAM
#define MAIN_PARAM int argc, char* args[]
#endif

#ifndef FRAME_VALUES
#define FRAME_VALUES 10
#endif

#ifndef SDL_GFX_X
#define SDL_GFX_X

////////////////SurfaceManip//////////////////
SDL_Surface *LoadImage(std::string filename);
void DrawRect(int x, int y, int w, int h, int red, int green, int blue, SDL_Surface* destination);
void PlaceText(int x, int y, std::string text, TTF_Font *font, SDL_Color textColor, SDL_Surface* destination);
void ApplySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
//////////////////////////////////////////////


//////////////////FPSCount////////////////////
void FPSinit();
void FPSmark();
std::string FPSget();

extern float framespersecond;
//////////////////////////////////////////////



////////////////////////////////////////////////////////
const SDL_Color WHITE = {255,255,255};
const SDL_Color BLACK = {0,0,0};
const SDL_Color BLUE = {17,43,171};
const SDL_Color RED = {195,13,13};
const SDL_Color GREEN = {14,158,14};
const SDL_Color YELLOW = {231,228,13};
const SDL_Color BROWN = {161,139,115};
const SDL_Color DARKBROWN = {121,99,75};
const SDL_Color GREY = {146,150,147};
const SDL_Color DARKGREY = {116,120,117};
const SDL_Color PURPLE = {104,15,173};
const SDL_Color AQUAMARINE = {12,180,178};

#endif



I'm not exactly sure what '__declspec(dllexport)' is, so I wasn't using it. My other dll, SDL_input, doesn't use it either, and it works fine. As far as I can see, the only problem is that SDL_gfx uses SDL_image and SDL_ttf. Is there a special way I'm suppose to include those to the DLL?

Share this post


Link to post
Share on other sites
Hmm, and I can use the SDL_Colors, just not the functions it seems. It doesn't appear to matter whether a particular function uses SDL_image or SDL_ttf functions, none of the functions work that I've tried.

[Edit:] Okay, it's working now. For others with the same problem, all I did was go to Porject -> Project Options -> Parameters and hit 'Add Library or Object' I then searched through my files and found my dll's object file, called SDL_gfx.o and added that. My final parameters looks like this:
../../../Dev-Cpp/lib/SDL_gfx.o
-SDL_gfx -lSDL_input -lSDL_image -lSDL_ttf
-lmingw32 -lSDLmain -lSDL


I don't understand why I need to link to the object file for SDL_gfx and not SDL_input, but it appears to be working none the less. Hope someone else benifits from this. Many thanks Bregma for your help!

[Edited by - Servant of the Lord on September 18, 2006 12:36:56 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
-SDL_gfx should be -lSDL_gfx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!