Problem with multiply defined symbols in a mixed-mode DLL

J

John

I have 5 native static libraries that are being compiled in Visual
Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all
managed code) in Visual Studio 2005 and the /MDd C Runtime setting.
They are in the same solution, and compile/link without problems (Debug
configuration).

I also have 1 mixed-mode CLR DLL that consumes both the static
libraries and managed DLLs. It is configured to use the /MDd C Runtime
library. When I add it to the solution (making sure its references are
correct), it gives linking errors shown below.

I am a relatively young developer, spoiled by Java and C#. I
understand that the problems indicate an attempt to link against 2
versions of the C Runtime Library -- but I have no idea what settings
to check (or what to look for in the code) in order to resolve the
problem. I have been making sure that C++ --> Code Generation -->
Runtime Library is set to /MDd for everything. Are there other
settings or places in code that could cause me to link to another
version?

Thanks for any advice you could give,
John

-----=[ Begin Example Linking Errors ]=-----
LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of
other libs; use /NODEFAULTLIB:library

libcpmtd.lib(cerr.obj) : error LNK2005: "public: __thiscall
std::basic_ostream said:
::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in msvcprtd.lib(MSVCP80D.dll)

LIBCMTD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
std::exception::exception(void)" (??0exception@std@@QAE@XZ) already
defined in MSVCRTD.lib(MSVCR80D.dll)

C:\path\MixedMode.dll : fatal error LNK1169: one or more multiply
defined symbols found
 
C

Carl Daniel [VC++ MVP]

John said:
I have 5 native static libraries that are being compiled in Visual
Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all
managed code) in Visual Studio 2005 and the /MDd C Runtime setting.
They are in the same solution, and compile/link without problems
(Debug
configuration).

I also have 1 mixed-mode CLR DLL that consumes both the static
libraries and managed DLLs. It is configured to use the /MDd C
Runtime
library. When I add it to the solution (making sure its references
are
correct), it gives linking errors shown below.

I am a relatively young developer, spoiled by Java and C#. I
understand that the problems indicate an attempt to link against 2
versions of the C Runtime Library -- but I have no idea what settings
to check (or what to look for in the code) in order to resolve the
problem. I have been making sure that C++ --> Code Generation -->
Runtime Library is set to /MDd for everything. Are there other
settings or places in code that could cause me to link to another
version?

Something in that mix was compiled with /MTd, not /MDd. Re-check your
project settings for everything in the link, and make sure to do a
Rebuild-All.

You can also use

dumpbin /directives myfile.obj (or .lib)

to see the defaultlib directives in an object or library file. That could
help you pin down which module is at fault.

-cd
 
J

John

Carl,

Thanks very much for telling me about the 'dumpbin' command: I never
knew about it. I've run it on one of the native libraries, and have
come up with the output below.

I can see that this library has "/DEFAULTLIB:LIBCMTD" but I'm confused
as to why because my C++ --> Code Generation --> Runtime Library is set
to "/MDd" and my librarian command line looks like the following:
/OUT:"Debug\native.lib" /NOLOGO /NODEFAULTLIB:"libcmtd.lib"
/NODEFAULTLIB:"libcpmtd.lib"

When I set my libraries and DLLs to compile with option /MDd, which C
Runtime Library should I expect to see in /dumpbin? libcmdd.lib?

As you can see, I've done enough searching/reading to know what my
problem is. But every time someone has this sort of problem, the
answer is always, "oh, just make sure you're linking against the same C
Runtime throughout" -- with no explaination of which settings to check
in the project's properties, so I'm very lost. =(

Can anyone please help me understand what my next steps should be?

Thanks!
John


-----=[ Begin /dumpbin output ]=-----
Microsoft (R) COFF/PE Dumper Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file native.lib

File Type: LIBRARY

Linker Directives
-----------------
/manifestdependency:"type='win32'
name='Microsoft.VC80.DebugCRT'
version='8.0.50608.0'
processorArchitecture='x86'
publicKeyToken='1fc8b3b9a1e18e3b'"
/DEFAULTLIB:"msvcprtd"
/manifestdependency:"type='win32'
name='Microsoft.VC80.DebugCRT'
version='8.0.50608.0'
processorArchitecture='x86'
publicKeyToken='1fc8b3b9a1e18e3b'"

/alternatename:__imp_??$?5DU?$char_traits@D@std@@@std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAD@Z=__imp_??5std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAD@Z
/DEFAULTLIB:"MSVCRTD"
/DEFAULTLIB:"OLDNAMES"

Linker Directives
-----------------
/DEFAULTLIB:"libcpmtd"
/DEFAULTLIB:"LIBCMTD"
/DEFAULTLIB:"OLDNAMES"

Linker Directives
-----------------
/DEFAULTLIB:"libcpmtd"
/DEFAULTLIB:"LIBCMTD"
/DEFAULTLIB:"OLDNAMES"

Linker Directives
-----------------
/DEFAULTLIB:"LIBCMTD"
/DEFAULTLIB:"OLDNAMES"

Linker Directives
-----------------
/DEFAULTLIB:"libcpmtd"
/DEFAULTLIB:"uuid.lib"
/DEFAULTLIB:"uuid.lib"
/include:?id@?$numpunct@D@std@@2V0locale@2@A

/include:?id@?$num_put@DV?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@2V0locale@2@A
/DEFAULTLIB:"LIBCMTD"
/DEFAULTLIB:"OLDNAMES"

Summary

E8 .CRT$XCU
6A1 .bss
685 .data
4CEB8 .debug$S
208 .debug$T
3EE .drectve
114D .rdata
9DD .rdata$r
14 .rtc$IMZ
14 .rtc$TMZ
19C .sxdata
1360A .text
135A .text$x
67B .text$yc
1A2 .text$yd
19E0 .xdata$x
 
C

Carl Daniel [VC++ MVP]

John said:
Carl,

Thanks very much for telling me about the 'dumpbin' command: I never
knew about it. I've run it on one of the native libraries, and have
come up with the output below.

I can see that this library has "/DEFAULTLIB:LIBCMTD" but I'm confused
as to why because my C++ --> Code Generation --> Runtime Library is
set
to "/MDd" and my librarian command line looks like the following:

OK, your project is set correctly. The next step is to check the settings
on every individual .cpp file in the project. Those settings can be
overridden on a file by file basis.
/OUT:"Debug\native.lib" /NOLOGO /NODEFAULTLIB:"libcmtd.lib"
/NODEFAULTLIB:"libcpmtd.lib"

I'm not sure that the /nodefaultlib option has any bearing on the lib
command (which is really just a wrapper over link /lib).
When I set my libraries and DLLs to compile with option /MDd, which C
Runtime Library should I expect to see in /dumpbin? libcmdd.lib?

You should see msvcrtd.lib
As you can see, I've done enough searching/reading to know what my
problem is. But every time someone has this sort of problem, the
answer is always, "oh, just make sure you're linking against the same
C
Runtime throughout" -- with no explaination of which settings to check
in the project's properties, so I'm very lost. =(

Can anyone please help me understand what my next steps should be?

-cd
 
J

John

Carl said:
OK, your project is set correctly. The next step is to check the settings
on every individual .cpp file in the project. Those settings can be
overridden on a file by file basis.

Carl,

That was the problem. I didn't know that individual files could
overwrite the project-level setting! Some of them were - as you can
guess - set to /MTd.

After resetting every single file (groan) for /MDd, everything compiles
and links!

Thanks so much!
John
 
C

Carl Daniel [VC++ MVP]

John said:
Carl,

That was the problem. I didn't know that individual files could
overwrite the project-level setting! Some of them were - as you can
guess - set to /MTd.

After resetting every single file (groan) for /MDd, everything compiles
and links!

Glad it worked!

Those per-file overrides are really handy when you need 'em, but quite a
nuisance when you don't know they're there! There were problems with
project conversion from VC6 to VC7 (and 7.1, I think) that would sometimes
duplicate project-level settings as file-level settings, so if your project
was migrated from VC6 through VC7.x, that may be how those per-file settings
got in there.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top