Resolving LNK2005 with a C, C++, and C++/CLI project

Go To StackoverFlow.com

0

I am getting linker errors when trying to build (there are a bunch... here is one such):

error LNK2005: "public: int __cdecl std::ios_base::rdstate(void)const " (?rdstate@ios_base@std@@QEBAHXZ) already defined in msvcprt.lib(MSVCP90.dll)

I have a C project:

  • Configuration Type: Static Libary (.lib)
  • Use of MFC: Use Standard Windows Libraries
  • Use of ATL: Not Using ATL
  • Runtime Library: Multi-threaded DLL (/MD)

I have a C++ project:

  • Configuration Type: Dynamic Library (.dll)
  • Use of MFC: Use Standard Windows Libraries
  • Use of ATL: Dynamic Link to ATL
  • Runtime Library: Multi-threaded DLL (/MD)

I have a C++/CLI project that relies on the two projects above:

  • Configuration Type: Dynamic Library (.dll)
  • Use of MFC: Use Standard Windows Libraries
  • Use of ATL: Dynamic Link to ATL
  • Runtime Library: Multi-threaded DLL (/MD)
  • Common Language Runtime Support (/clr)
  • This links to the C project .lib
  • This has a project reference to the C++ DLL

These are built using the Visual 2010, but with the v3.5 toolset (so using 9.0).

Most solutions I've seen suggest that the Runtime library settings are not in sync. This is not the case here, they're all Multi-threaded DLL. They're all built in Release x64.

Does anything jump out with these project settings? Are there any more relevant settings I could share?

2012-04-05 14:57
by Jason X
Surely the toolset is the problem here. With the linker error produced by both linking the VS2010 and the VS2008 version of msvcprt.lib. Check the C project and make sure it's vcxproj contains the required property - Hans Passant 2012-04-05 15:08
It says "already defined in ..." does it say where else it is defined? Maybe in the rows before this message - selalerer 2012-04-05 15:10
@HansPassant Under Configuration Properties > Generic > Platform Toolset, each project is set to v90. This is also reflected in the .vcxproj files: v90Jason X 2012-04-05 15:42
Well, do try to eliminate that as the possible cause first. Does the link error disappear when you just let everything build with the default toolset? More diagnostics are available by using the linker's /VERBOSE command line option. That gives a trace of every .lib being linked - Hans Passant 2012-04-05 15:52
Does the C or C++ project link to anything else? Any third party libraries - syplex 2012-09-19 23:02


0

I'd suggest to use the same setting everywhere and not mixing (static library and dll projects). If I remember well I ran into the same issue.

2013-04-22 17:09
by the baconing
Ads