Linker Errors : Static linking both STL and C code 
Author Message
 Linker Errors : Static linking both STL and C code

Gurus,

My project has both .C files and .CPP files. The CPP code uses STL. I
am trying to statically link this code. Its a single threaded
application. When I try to build the project I get following errors:

--------------------Configuration: TestProject - Win32
Debug--------------------
Linking...
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in
LIBCD.lib(strncpy.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strchr already defined in
LIBCD.lib(strchr.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in
LIBCD.lib(fclose.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fflush already defined in
LIBCD.lib(fflush.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in
LIBCD.lib(sprintf.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncmp already defined in
LIBCD.lib(strncmp.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _toupper already defined in
LIBCD.lib(toupper.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _malloc already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _calloc already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _realloc already defined in
LIBCD.lib(dbgheap.obj)
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _free already defined in
LIBCD.lib(dbgheap.obj)
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of
other libs; use /NODEFAULTLIB:library
Debug/TestProject.exe : fatal error LNK1169: one or more multiply
defined symbols found
Error executing link.exe.

TestProject.exe - 12 error(s), 1 warning(s)

--------------------------------------------------------------------------------

I tried specifying MSVCRTD.lib in the /NODEFAULTLIB list but no luck.
I get more errors related to C libraries.

Does anyone know how to resolve this error?

Thanks and regards,

~Ajit



Sat, 09 Apr 2005 01:24:36 GMT  
 Linker Errors : Static linking both STL and C code
Your static library is linked against Debug Single-threaded CRT, but the
project you are trying to use it with links to Debug Multithreaded DLL
CRT. You need both linked to the same CRT flavor.

See Project | Settings | C/C++ | Code generation | Use run-time library.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Gurus,

> My project has both .C files and .CPP files. The CPP code uses STL. I
> am trying to statically link this code. Its a single threaded
> application. When I try to build the project I get following errors:

> --------------------Configuration: TestProject - Win32
> Debug--------------------
> Linking...
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in
> LIBCD.lib(strncpy.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strchr already defined in
> LIBCD.lib(strchr.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fclose already defined in
> LIBCD.lib(fclose.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fflush already defined in
> LIBCD.lib(fflush.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _sprintf already defined in
> LIBCD.lib(sprintf.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _strncmp already defined in
> LIBCD.lib(strncmp.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _toupper already defined in
> LIBCD.lib(toupper.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _malloc already defined in
> LIBCD.lib(dbgheap.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _calloc already defined in
> LIBCD.lib(dbgheap.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _realloc already defined in
> LIBCD.lib(dbgheap.obj)
> MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _free already defined in
> LIBCD.lib(dbgheap.obj)
> LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of
> other libs; use /NODEFAULTLIB:library
> Debug/TestProject.exe : fatal error LNK1169: one or more multiply
> defined symbols found
> Error executing link.exe.

> TestProject.exe - 12 error(s), 1 warning(s)

> ----------------------------------------------------------------------
----------

> I tried specifying MSVCRTD.lib in the /NODEFAULTLIB list but no luck.
> I get more errors related to C libraries.

> Does anyone know how to resolve this error?

> Thanks and regards,

> ~Ajit



Sat, 09 Apr 2005 01:49:33 GMT  
 Linker Errors : Static linking both STL and C code

Quote:

> Gurus,

> My project has both .C files and .CPP files. The CPP code uses STL. I
> am trying to statically link this code. Its a single threaded
> application. When I try to build the project I get following errors:

> --------------------Configuration: TestProject - Win32

> TestProject.exe - 12 error(s), 1 warning(s)

> --------------------------------------------------------------------------------

> I tried specifying MSVCRTD.lib in the /NODEFAULTLIB list but no luck.
> I get more errors related to C libraries.

> Does anyone know how to resolve this error?

> Thanks and regards,

> ~Ajit

Did you build static linked library? In this case if you use run-time
library in the lib and the application then your must compile the
application with same version of run-time library (Release/Debug,
Singlethread/multithread/multithread dll) as your library. I recommend
build 6 difference versions of library and use special header file for
link needfull version of lib into your project. It likes USE_ANSI.H
file from MS STL.
---------------------------------
Konstantin
AlarIT developer
http://www.alarit.com


Sat, 09 Apr 2005 21:03:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linker Errors : Static linking both STL and C code

2. stl, managed code load & link errors

3. stl, managed code load & link errors

4. Error linking static MFC and static C/C++ runtime

5. Linking Error - Static vs. Non-Static

6. VC 4.2 link error linking static libraries from VC 6.0

7. Link Errors in Static Link

8. Link errors during static link

9. STL queue linker error moving from VC6 to VC7

10. LNK2001: linker error w/ static lib's for beginthreadex and endthreadex

11. SGI STL/string and non-static links

12. Linker Error with MSDIS100.DLL - Cannot find entry point during the Link

 

 
Powered by phpBB® Forum Software