VC++ (weird) Linking error ..
Brian Knudsen

It started giving linking errors just ealier this night .. it worked for me all day, but my project suddenly didnt want to link. Can anyone explain what is happaning and why ?

first error

Linking...
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBC.lib(fclose.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _fopen already defined in LIBC.lib(fopen.obj)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _sprintf already defined in LIBC.lib(sprintf.obj)
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
Release/misc.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

then i tried /nodefaultlib:"msvcrt" that had worked before .. but now i get :
second error:

Linking...
LINK : warning LNK4049: locally defined symbol "_fclose" imported
LINK : warning LNK4049: locally defined symbol "_fopen" imported
LINK : warning LNK4049: locally defined symbol "_sprintf" imported
test.obj : error LNK2001: unresolved external symbol __imp__rand
test.obj : error LNK2001: unresolved external symbol __imp__srand
test.obj : error LNK2001: unresolved external symbol __imp__time
test.obj : error LNK2001: unresolved external symbol __imp___errno
Release/misc.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

---

so here i am .. pretty stuck ..

gillius

Are you mixing different versions of the C runtime library?

Have you tried cleaning your project and rebuilding? If you have changed versions of MSVC, versions of the standard library, or project settings, object files can become imcompatible.

Have you defined any functions that are of the same name as any of the runtime's functions?

Either ways, this is a runtime problem. Some object files are using one runtine while other object files are using another.

Those are some pretty funky errors and represents some sort of serious misconfiguration issue with respect to linking of the standard libs.

Brian Knudsen

it came out of nowhere .. i have had need to define nodefaultlib before, but now it wont even link with that .. i have a backup some days old, think ill take it from there .. but i think there is something rotten even from start .. but cant find what ... hmm, guess i have to look at my backup and take from there .. :(

Oscar Giner

try /nodefaultlib:libc

I have to put that if I don't want a warning when linking, but you get errors, so I don't know if that will work

Brian Knudsen

Thanks a million times !!!!

/nodefaultlib:libcd for debug and /nodefaultlib:libc for release ..

EXCELLENT answer ..

But why did this habben ? why does libc conflict with msvcrt lib ?

Bruce Perry

I'd like an answer to this question too, since people have this problem linking with DUMB sometimes. Bob gave me an answer about mixing the single-threaded (/ML) and multithreaded (/MD) versions of the library, but I e-mailed someone with that and they said it didn't fix the problem.

Why exactly does /nodefaultlib:libc(d) fix it?

Bob

/nodefaultlib:libc removed the dependency on libc.

This doesn't always work however. The real solution is to not mix up Multithreaded DLL with Single threaded static libs. This means that all the libraries that use std C functions need to be compiled with the same C run-time.

Izual

I have another problem with linking. If i use ALLEGRO STATIC LIB a get Linking error 2001: unresolved external symbol _imp_allegro_init and for all functions from ALLEGRO i have used in my program. But if i use DLL version of ALLEGRO it work perfect.
Im using MSVC++ 6.0. ALLEGRO 4.02. Both libs are compiled: FIX MSVC foloving MAKE foloving MAKE INSTALL. Is something wrong with ALLEGRO or am i doing something wrong?
Can you help me? :'(

Thomas Fjellstrom

um. w0w. I thought 'allegro_init' was just a #define for 'install_allegro(SYSTEM_AUTODETECT, &errno, &atexit)'.. you shouldn't be getting an unresolved symbol error for 'allegro_init'.

Matthew Leverton

If you static link, you'll need to link against all the various Win32 libs. See the docs for more information.

Thread #207077. Printed from Allegro.cc