• Create Account

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a \$50 Amazon gift card. Click here to get started!

# Linking Problems (How is this even possible?)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1OmarShehata  Members   -  Reputation: 205

Like
0Likes
Like

Posted 29 February 2012 - 11:55 PM

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!

### #2RulerOfNothing  Members   -  Reputation: 1320

Like
1Likes
Like

Posted 01 March 2012 - 12:22 AM

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.

### #3bradbobak  Members   -  Reputation: 1366

Like
0Likes
Like

Posted 01 March 2012 - 12:22 AM

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.

### #4OmarShehata  Members   -  Reputation: 205

Like
0Likes
Like

Posted 01 March 2012 - 07:35 AM

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...

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS