2

I am trying to recompile some code I have for a new system. It involves a precompiled static library that I do not have the source code for (just the header), and this library was built with VC++ 6.0 or older with the older runtime libraries. On my old system, which had VC++ 6.0, my program was built and ran fine, but I have recently upgraded things and I no longer have access to VC++ 6.0, only Express 2008 (9.0 w/ SP).

When I build the solution, it compiles but has the following linker error:

1>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z) already defined in NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z) already defined in NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ) already defined in NOREC.lib(track.obj) 1>LINK : fatal error LNK1104: cannot open file 'libcp.lib'

Any ideas how to overcome this issue would be very welcome.

dirkgently
  • 108,024
  • 16
  • 131
  • 187
jjl3
  • 47
  • 1
  • 3

4 Answers4

4

From the last link error, libcp.lib cannot be found. This library has been removed as of VS 2005. Use /MT for the multithreaded version.

http://msdn.microsoft.com/en-us/library/abx4dbyh%28v=vs.80%29.aspx

The multithreaded version is libcpmt.lib which you will get automatically with the /MT flag. I see in the first error you are using libcpmtd.lib which is the debug version of the same. I'm not sure how you are getting that if you are not using /MTd. (or if you are, how libcp.lib is referenced since you should be using one or the other, not both)

Dave Rager
  • 8,002
  • 3
  • 33
  • 52
  • What you have said is true, but it is not relevant in this case -- I AM using /MT, but I am not compiling the static library that is calling for that library. I was wondering if there was a way to do overcome this without rebuilding the library (I dont have access to the source code). – jjl3 May 30 '12 at 21:03
  • If you are using `/MT` then check your "Additional libraries" path (I don't know what VS2008 calls it) to make sure `libcpmtd.lib` and `libcp.lib` were not added manually. They are basically different versions of the same runtime, one debug multithreaded, the other single threaded. And since the single threaded version was removed altogether it definitely shouldn't be in your build config at all. – Dave Rager May 30 '12 at 21:08
  • The old library was compiled with the old run time libraries... and I know thats what is causing this problem, but I don't know if there is a way that I can make this work. I assume the method is neither simple nor elegant, but it could shave 6 months to a year off my PhD – jjl3 May 30 '12 at 21:12
  • I checked the config, there is no reference to it at all. – jjl3 May 30 '12 at 21:13
  • I wouldn't think a static library would have any linkage dependencies at this point since technically they aren't "linked" yet. Of course this is MS. I've fought these battles with third party DLLs before but that's understandable. Static not so much. Sorry I don't have more. – Dave Rager May 30 '12 at 21:26
1

The linker is telling you that some symbols are defined more than once. The brute force to convice the linker to produce your target image is to use the /FORCE:MULTIPLE as explained here. I used to use this switch a few times.

mox
  • 6,084
  • 2
  • 23
  • 35
  • 1
    Thanks, that turns the first set of errors to warnings (and hopefully there will be no run time errors with that). The error that really scares me is unchanged, the fatal error LNK1104: cannot open file 'libcp.lib', which I assume is related to the fact that NOREC.lib needs the obsolete runtime libraries. Any ideas about how to get this work? – jjl3 May 30 '12 at 20:53
  • My guess is that there will be no run time errors with that (since this was a link failure telling you that you took one or more libs into account). As Daver Rager mentioned, libcp.lib as been removed as of VS2K5. Remove this lib from your project. – mox May 31 '12 at 05:24
0

LINK : fatal error LNK1104: cannot open file 'libcp.lib'

This is a bug in the linker. Just create an empty file named libcp.lib in the LIBPATH.

John
  • 1
-1

libcp.lib you can find in installed MS Visual Studio 6.0 in

c:\Program Files\Microsoft Visual Studio\VC98\Lib\ 

directory.

Just copy it to your MSVS 2005/2008/2010 lib directory (i.e. c:\Program Files\Microsoft Visual Studio 8\VC\lib\) And everything will compiled just fine.

Robert
  • 5,278
  • 43
  • 65
  • 115