Sign in to follow this  
XTAL256

Linking problems *SOLVED*

Recommended Posts

Hi, i am using a small XML library with my game (i gave up on using my friend's code, if you read my other post). I compiled it into a .lib and linked it with my project. But i get link errors:
Generating Code...
Linking...
SOIL.lib(SOIL.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
IconButton.obj : error LNK2001: unresolved external symbol "public: char const * __thiscall XMLNode::getAttribute(char const *,int *)const " (?getAttribute@XMLNode@@QBEPBDPBDPAH@Z)
Label.obj : error LNK2001: unresolved external symbol "public: char const * __thiscall XMLNode::getAttribute(char const *,int *)const " (?getAttribute@XMLNode@@QBEPBDPBDPAH@Z)
Panel.obj : error LNK2001: unresolved external symbol "public: char const * __thiscall XMLNode::getAttribute(char const *,int *)const "
...


That is a snippet of the link errors, there are more but they are all the same. I tweaked the XML code before i compiled it into the .lib but that shouldn't matter because i made sure i included the modified .h and .lib file in my game project. So i don't see why i am getting these link errors, is it maybe some conflicting settings in Visual Studio? (btw, i am using WinXP, MSVC, and SDL). I tried reading the MSVC help on link error LNK2001 but i don't know where to start, i don't know what could be causing the error. If anyone has the slightest idea on what i have done wrong, or if you would like to see my full code, i would be very grateful. thanks [Edited by - XTAL256 on July 5, 2008 6:21:52 PM]

Share this post


Link to post
Share on other sites
somewhat unrelated but i added /NODEFAULTLIB:LIBCMT.lib to resolve LNK4098 but it didn't solve my problem. I would post my code but it's a bit messy since i am changing all my code to use the new XML library so i will only post it if anyone would like to see it.

Share this post


Link to post
Share on other sites
Did you check if you build the xml library with the same runtime library option as your project? (Project Configuration -> C/C++ -> Code Generation ... Multi-threaded Debug (/MTd), ...)

h.

Share this post


Link to post
Share on other sites
Quote:
Original post by XTAL256
somewhat unrelated but i added /NODEFAULTLIB:LIBCMT.lib to resolve LNK4098 but it didn't solve my problem. I would post my code but it's a bit messy since i am changing all my code to use the new XML library so i will only post it if anyone would like to see it.
What version of visual studio? I haven't seen that error since VC6...

The linker errors you're getting means that the compiler/linker doesn't know where to find the implementation of XMLNode::getAttribute(). Make sure that the library has that function in it, the .lib is linked into the project in your project settings, and the .lib is compiled with the same version of visual studio as your exe.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
What version of visual studio? I haven't seen that error since VC6...

Honestly, i have no idea why i get errors like that. I don't know what LIBCMT.lib is, probably some sort of C runtime library. I also need to exclude MSVCRT.lib from linking and i don't know why i have to do that either. But that's not really a worry to me, i just include/exclude whatever libraries are needed for the project.

Quote:
Original post by Evil Steve
The linker errors you're getting means that the compiler/linker doesn't know where to find the implementation of XMLNode::getAttribute(). Make sure that the library has that function in it, the .lib is linked into the project in your project settings, and the .lib is compiled with the same version of visual studio as your exe.

Yeah, i know all that. That's what i was talking about in my first post. I said "I compiled it into a .lib", so i know that the VS version is the same as my project. "i made sure i included the modified .h and .lib file in my game", so yeah, i did all that. But other than that i don't know what else is wrong.

@hoLogramm: ah, that's another thing i don't know about [embarrass]. I have my game project set as "debug" and use "Multi-threaded Debug DLL (/MDd)". I compiled the XML lib as "release" (since the author says it's a lot faster in release mode) and "Multi-threaded (/MT)". That was already set in the VS project that came with the library code i downloaded. It also has "Function-Level Linking" set (i don't know what that is either). I set the XML project to "Multi-threaded DLL" but it still didn't work. Can i use non-debug runtime with the XML library and use it with my project in "debug" mode?

Share this post


Link to post
Share on other sites
Quote:
@hoLogramm: ah, that's another thing i don't know about [embarrass]. I have my game project set as "debug" and use "Multi-threaded Debug DLL (/MDd)". I compiled the XML lib as "release" (since the author says it's a lot faster in release mode) and "Multi-threaded (/MT)". That was already set in the VS project that came with the library code i downloaded. It also has "Function-Level Linking" set (i don't know what that is either). I set the XML project to "Multi-threaded DLL" but it still didn't work. Can i use non-debug runtime with the XML library and use it with my project in "debug" mode?


Yes, you can mix debug and release versions. Libraries compiled in release mode only means, that they don't contain any debug symbols.
The problem i see is that you compiled with multi-threaded and multi-threaded dll. Change both to multi-threaded (debug or release) and that should fix your problem.

Quote:

Honestly, i have no idea why i get errors like that. I don't know what LIBCMT.lib is, probably some sort of C runtime library. I also need to exclude MSVCRT.lib from linking and i don't know why i have to do that either. But that's not really a worry to me, i just include/exclude whatever libraries are needed for the project.

libcmt.lib ... static link library for c++ (release)
libcmtd.lib .. same only for debug
msvcrt.lib ... dynamic link library for c++ (release)
msvcrtd.lib ... same only for debug
libc.lib, libcd.lib ... c libraries

find out more here

Because those are standard libraries which get included automatically, you have to ignore all versions that don't match your build environment, since they define the same function set.

e.g.
I ignore these libraries, when building my project in static debug mode:
libcmt.lib msvcrt.lib msvcrtd.lib libc.lib libcd.lib

and in static release mode:
libcmtd.lib msvcrt.lib msvcrtd.lib lic.lib libcd.lib

h.

Share this post


Link to post
Share on other sites
Quote:
Original post by hoLogramm
The problem i see is that you compiled with multi-threaded and multi-threaded dll. Change both to multi-threaded (debug or release) and that should fix your problem.

Is there any reason why i must change them to multi-threaded and not multi-threaded dll? Because after i last posted, i changed the XML lib to match my project's settings (multi-threaded debug DLL) but i still got the link errors. I will try changing both to multi-threaded.

Share this post


Link to post
Share on other sites
Ok, i changed my game project and the XML lib to multi-threaded (debug and release respectively) and it still doesn't work. I will post the project settings in case there is anther reason why i might be getting this error:

Ballistic (my game) project:

C++ compiler:
/Od /I "C:\...\Ballistic\src\\" /D "WIN32" /D "_DEBUG" /FD /EHsc /MDd /fp:fast
/Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Zi /TP /errorReport:prompt

Linker:
/OUT:"..\\Ballistic.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST
/MANIFESTFILE:"Debug\Ballistic.exe.intermediate.manifest" /NODEFAULTLIB:"MSVCRT"
/NODEFAULTLIB:"LIBCMT" /DEBUG /ASSEMBLYDEBUG
/PDB:"c:\...\Ballistic\src\Debug\Ballistic.pdb" /SUBSYSTEM:WINDOWS
/ENTRY:"mainCRTStartup" /MACHINE:X86 /ERRORREPORT:PROMPT
"C:\...\Ballistic\src\soil\SOIL.lib" "C:\...\Ballistic\src\utils\dirent.lib"
"C:\...\Ballistic\src\utils\xmlParser.lib" user32.lib ole32.lib gdi32.lib
OpenGL32.lib GLu32.lib GLaux.lib SDL.lib SDLmain.lib SDL_mixer.lib kernel32.lib


XML library project:

C++ compiler:
/O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0x0600" /D
"_UNICODE" /D "UNICODE" /GF /FD /EHsc /MD /Gy /Fp".\Release/xmlParser.pch"
/Fo".\Release/" /Fd".\Release/" /W3 /nologo /c /TP /errorReport:prompt

Librarian:
/OUT:".\Release\xmlParser.lib" /NOLOGO

NOTE: I have abbreviated the project path with ... and I copy the .lib file from ".\Release" to the path shown above.

Share this post


Link to post
Share on other sites
This error isn't related to CRT library. (Link warnings are, though) I think the problem can be completely solved if you can post the whole source. (It's silly, I know) What I could imagine is:

- Are you sure the .cpp file(s) which contain the implementation of XMLNode class are included in the XML project?
- Isn't it possible the implementations are excluded via preprocess directives, such as #ifdef-#endif?

And if you can post the xmlParser.lib file, I can tell more informations.

Regards

Share this post


Link to post
Share on other sites
Ohh!! I didn't think you'll share your complete source! It's a hard decision.
OK anyways, I found the reason - you built xmlParser library as unicode version and your project ansi version.

The xmlParser.lib does contain XMLNode::getAttribute() function, but the signature is:
public: wchar_t const * __thiscall XMLNode::getAttribute(wchar_t const *,int *)const 



And the function your compiler is expecting from that library is (from the error message you post):
public: char const * __thiscall XMLNode::getAttribute(char const *,int *)const 



So, everything is clear now. Either you can compile the xmlParser library as ansi version, or build your application in unicode version.

Glad that I could help

Share this post


Link to post
Share on other sites
Quote:
Original post by 1hod0afop
OK anyways, I found the reason - you built xmlParser library as unicode version and your project ansi version.

Ah, you know, i was just about to try that. Yesterday i was comparing the setting that i posted for each project and trying to see the differences. I noticed that i didn't have my game project set as unicode, i realised that i didn't want it as unicode anyway because by bitmap fonts are only ASCII characters anyway, and if i wanted to build an international version i could change to unicode then. So today, just after i read this post, i was going to change the XML lib to non-unicode. Thanks for your help anyway.

Quote:
Original post by 1hod0afop
Ohh!! I didn't think you'll share your complete source!

Yeah, well i didn't know how much of it you needed, i though you may want to try and compile it. So i just zipped the whole thing, it's only 2Mb [grin].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this