3

So, I'm building a static C++11 Windows Library A.lib which uses 'PocoFoundationmt.lib' and a few other third party libraries and I don't want to have the Test application (Z.exe) which uses A.lib to have a long list of all libraries in the linker command. So, I want to merge all the third party libraries into a composite.lib

The project for A.lib is generated by cmake and the CMakeLists.txt file has the following lines:

add_library(A STATIC ${SOURCES})

target_link_libraries(A PRIVATE PocoFoundationmt.lib OtherStaticLibs.lib)

Now, after I build A.lib, I execute LIB.EXE to combine libraries as suggested in a lot of threads:

eg. Linking static libraries to other static libraries

LIB.EXE /OUT:composite.lib A.lib PocoFoundationmt.lib OtherStaticLibs.lib

However, when I link the composite.lib to my Test application, it always throws this error :

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

A lot of threads suggested to combine libraries this way. Is this the correct approach or do I have to mention all libraries in the linker input parameter of my Test app (Z.exe) ?

Community
  • 1
  • 1
MMi
  • 41
  • 3
  • You should pass absolute paths to `target_link_libraries()`. – arrowd Sep 23 '16 at 12:07
  • @drescherjm I am combining the libraries using /MACHINE:x86 option. All my static libraries are also 32-bit. Also, PocoFoundationmt.lib works fine when I link it with my Test project so I know that is not a corrupt file. It's just that if I combine PocoFoundationmt.lib and other 3rd party libraries in one library that I see this issue. – MMi Sep 23 '16 at 14:07
  • @arrowd I am passing the absolute paths. I wrote this just as an example. Sorry for that. – MMi Sep 23 '16 at 14:09
  • I see the problem is `PocoFoundationmt.lib` is still in linker libraries for Test. You need to get it out of the list if you want to use the combined library. Is it listed in Linker/ Input / Additional Dependencies for Test? If it is not perhaps there is a `#pragma comment (lib, PocoFoundationmt.lib)` in one of your headers. – drescherjm Sep 23 '16 at 14:31
  • @drescherjm No, PocoFoundationmt.lib is not listed anywhere, neither in Additional Dependencies nor there is a pragma comment anywhere. – MMi Sep 23 '16 at 14:43
  • The libraries that you are combining are all static libraries (not import libraries / no dlls involved)? – drescherjm Sep 23 '16 at 14:46
  • @drescherjm Yes. All Poco libraries are created with POCO_STATIC enabled and other libraries are also static. And I was just able to successfully build the Test project by including the directory where PocoFoundationmt.lib is present in the Linker / General / Additional Library Directories. I'm not sure why this is happening. – MMi Sep 23 '16 at 15:03
  • ***I'm not sure why this is happening.*** Me either. – drescherjm Sep 23 '16 at 15:08

0 Answers0