Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / August 2006

Tip: Looking for answers? Try searching our database.

Problem with multiply defined symbols in a mixed-mode DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 11 Aug 2006 23:51 GMT
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<char,struct std::char_traits<char>
>::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
Carl Daniel [VC++ MVP] - 12 Aug 2006 05:15 GMT
> 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
[quoted text clipped - 18 lines]
> 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
John - 14 Aug 2006 18:50 GMT
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
John - 14 Aug 2006 19:14 GMT
I've answered one of my own questions but still have a long way to go..

> 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?

The article at http://msdn2.microsoft.com/en-us/library/2kzt1wy3.aspx
answers this question.

Also, http://msdn2.microsoft.com/en-us/library/abx4dbyh.aspx is another
resource.
Carl Daniel [VC++ MVP] - 15 Aug 2006 04:10 GMT
> Carl,
>
[quoted text clipped - 6 lines]
> 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
[quoted text clipped - 4 lines]
>
> Can anyone please help me understand what my next steps should be?

-cd
John - 15 Aug 2006 21:05 GMT
> 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
Carl Daniel [VC++ MVP] - 15 Aug 2006 21:45 GMT
>> OK, your project is set correctly.  The next step is to check the
>> settings
[quoted text clipped - 9 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.