Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » VC++ (weird) Linking error ..

This thread is locked; no one can reply to it. rss feed Print
VC++ (weird) Linking error ..
Brian Knudsen
Member #1,852
January 2002

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
Member #119
April 2000

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.

Gillius
Gillius's Programming -- https://gillius.org/

Brian Knudsen
Member #1,852
January 2002

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
Member #2,207
April 2002
avatar

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
Member #1,852
January 2002

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
Member #270
April 2000

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?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Bob
Free Market Evangelist
September 2000
avatar

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

--
- Bob
[ -- All my signature links are 404 -- ]

Izual
Member #2,756
September 2002
avatar

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
Member #476
June 2000
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

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

Go to: