Jump to content
  • Advertisement
Sign in to follow this  
OmarShehata

Linking Problems (How is this even possible?)

This topic is 2479 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

So wanting to display fonts in my openGL app, I download this nifty little library:

http://ftgl.sourceforge.net/docs/html/index.html

Put the source in my code, add a linker directory to src/ so it finds the stuff, and it seems to be linking well. Okay good.

So the tutorial says to create a font object like this:


FTGLPixmapFont font("/home/user/Arial.ttf");


Now it outputs an undefined error:

\InitGame.cpp|15|undefined reference to `FTPixmapFont::FTPixmapFont(char const*)'|
\InitGame.cpp|42|undefined reference to `FTPixmapFont::~FTPixmapFont()'|
\InitGame.cpp|42|undefined reference to `FTPixmapFont::~FTPixmapFont()'|
||=== Build finished: 3 errors, 0 warnings ===|



I keep checking if everything is in the correct folder, and they are. Now what's driving me nuts is if I do:


FTGLPixmapFont font(2); //Initlizing the variable with an incorrect argument


The output is:


\InitGame.cpp|15|error: invalid conversion from 'int' to 'const char*'|
\InitGame.cpp|15|error: initializing argument 1 of 'FTPixmapFont::FTPixmapFont(const char*)'|
||=== Build finished: 2 errors, 0 warnings ===|


So it can find the function, it knows it's supposed to take a "char", and it finds the class and everything. Yet when I put back the correct argument, suddenly it's undefined. I'm still hazy on the rules of linking, but I thought I did everything correct, I can't explain why this could be happening.

Any help would be appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Technically the file with the definition of FTGLPixmapFont's constructor is not in the src directory, but the src/FTFont directory, so the linker probably can't find the definition. The behaviour you describe is due to the fact that the second error message is a compiler error (due to the fact that using an incorrect argument can be discovered during the compile phase rather than the link phase). To solve this problem, you could probably put src/FTFont/ in the linker directories.

Share this post


Link to post
Share on other sites
You need to link this library into your executable. With g++ its something like 'g++ -Ldirectory_of_lib -lthe_lib_name'
In visual studio, I'm not sure, but I think theres somewhere in the options what libraries to link in at compile time.

EDIT: My mistake. Didn't notice you said it was linking fine.

Share this post


Link to post
Share on other sites

Technically the file with the definition of FTGLPixmapFont's constructor is not in the src directory, but the src/FTFont directory, so the linker probably can't find the definition. The behaviour you describe is due to the fact that the second error message is a compiler error (due to the fact that using an incorrect argument can be discovered during the compile phase rather than the link phase). To solve this problem, you could probably put src/FTFont/ in the linker directories.


Damnit, I keep forgetting how everyone declares function prototypes in the headers but the actual body is in the cpp files. Thanks for the heads up!

Ok, so scanning the code, I can't seem to find anything that loads FTPixmapFont.cpp. So I manually include that file in my code, and I get the error that it can't find a file called "config.h". FTPixmapFont.cpp is trying to include that file..but it doesn't seem to be anywhere in the source...

Why isn't anything ever straightforward?

EDIT: Ok, there's definitely something wrong here, if I remove the include "config.h" line, I get an error in FTPixmapFont.cpp that it can't find an FTFont function..which makes sense because again..FTFont.cpp is *not* included anywhere in main header file, that the tutorial says only that should be included.

It seems that if I simply modify that file to include the rest of the source files, then it should work...but I'm hesitant about that because y'know, you'd assume an engine like this to not have such an obvious mistake...

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!