Linker Errors

Started by
4 comments, last by phresnel 15 years, 2 months ago
I suck at knowing how linkers work. I gather that this problem, or variants of it, are relatively common, but I don't know how to deal with it. I'm working on a game which makes use of several external libraries (OpenGL, GLUI, jpeg, audiere, and Box2D), and I've been trying to switch the base code to manage the window and input from freeglut to SDL. I've got everything compiling properly after the switch to SDL, but I've got the following linker errors and I don't know how to fix them:
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _exit already defined in LIBCMTD.lib(crt0dat.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _strrchr already defined in LIBCMTD.lib(strrchr.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
1>msvcrt.lib(MSVCR90.dll) : error LNK2005: __isctype already defined in LIBCMTD.lib(isctype.obj)
1>LIBCMTD.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Any ideas?
"We two, the World and I, are stubborn fellows at loggerheads, and naturally whichever has the thinner skull will get it broken" - Richard Wagner
Advertisement
You'd linking in two conflicting C runtime libraries. See this thread I found on google (I have to run so I can't type out a full explanation):

http://forums.devx.com/archive/index.php/t-94592.html
That explained some of it, and I've looked up what Microsoft has to say about it here: http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx , but I still don't quite know what's going on or what to do about it. My "Runtime Library" option is set in the project properties as "Multi-Threaded (/MT)" (or /MTd for debug builds), so I guess my project uses libcmt.lib (or libcmtd.lib). I don't do any multithreading in my code, but perhaps it happens in some of the libraries - either way, it's what the default setting was when I started the project, and it's not proved to be a problem up until now.

So... This linker error is telling me that "something" is using /MD, msvcrt.lib, and that it shouldn't be - is that right? If so, how do I tell what that "something" is? I'm guessing that SDL is the culprit because that's what I'm putting into the project, but I'd rather have a way to know these things than to just guess.

Assuming it is SDL, what can I do? Download the source code and try to compile an SDL DLL using /MT instead of /MD? Will that even work?
"We two, the World and I, are stubborn fellows at loggerheads, and naturally whichever has the thinner skull will get it broken" - Richard Wagner
Do this:
Quote:
Solution Two: Locate and Correct the Problem Module
To view the current library link order, follow these steps:

1. On the Project menu, click Settings.
2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
3. On the Link tab, type /verbose:lib in the Project Options box.
4. Rebuild your project. The libraries will be listed in the output window during the linking process.

Then search for every mention of LIBCMTD.lib and MSVCR90.dll and msvcrt.lib.

Read the chain of dependencies that results in each library being pulled in. See if anything is going wrong in the chain.
Those instructions don't seem to come from the IDE I'm using (Visual Studio 2008, for what it's worth). I don't have a Settings option in my Project menu, for instance.

I ended up grabbing the full SDL source code (rather than just a precompiled DLL and headers, which I had been using), and ignoring the instructions to build using /MD, choosing /MT instead. I didn't think it would work, but it has. I still don't really understand the difference between the different runtimes, and I'd like to, but everything is working for me at least. Of course I've got other problems now, but that's a different story :)
"We two, the World and I, are stubborn fellows at loggerheads, and naturally whichever has the thinner skull will get it broken" - Richard Wagner
Minor addition:
Quote:Original post by NotAYakk
Do this:
Quote:

Original post by support.microsoft.com


Solution Two: Locate and Correct the Problem Module
To view the current library link order, follow these steps:

1. On the Project menu, click Settings.
2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
3. On the Link tab, type /verbose:lib in the Project Options box.
4. Rebuild your project. The libraries will be listed in the output window during the linking process.

Then search for every mention of LIBCMTD.lib and MSVCR90.dll and msvcrt.lib.

Read the chain of dependencies that results in each library being pulled in. See if anything is going wrong in the chain.


[smile]

This topic is closed to new replies.

Advertisement