Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake linking against shared library on windows: error about not finding .lib file

Tags:

c++

windows

cmake

I've got a library definition in CMake that builds a shared library out of a small set of files, and I've got it compiling just fine on both linux and windows.

However, I've also got another library that links against the shared library and it works fine on linux, however, on windows I get a message along the lines or "error can't find Release/nnet.lib" during link-time. Is there something special I have to do to get this to link on windows?

Edit, example:

Main shared library (filenames changed to protect the innocent):

ADD_LIBRARY(nnet SHARED
  src/nnet/file_1.cc src/nnet/file_3.cc  
  src/nnet/file_2.cc src/nnet/file_4.cc)

And then I'm building a python module that links in the library:

# Build python module
ADD_LIBRARY            (other_lib SHARED ${CMAKE_SOURCE_DIR}/src/boost/boost_main.cc)
TARGET_LINK_LIBRARIES  (other_lib nnet   ${PYTHON_LIBRARIES})

The rest is just boilerplate (eg: changing module extension to .pyd on windows, finding python libraries/headers, etc) And then when building in VS 2008 I get:

fatal error LNK1181: cannot open input file 'Release\nnet.lib'

when building other_lib. Note no errors are thrown while building nnet.

like image 924
gct Avatar asked Feb 03 '23 07:02

gct


1 Answers

Ah, my problem was I forgot to include a __declspec(dllexport) in suitable places when building the library (can you tell I don't do windows programming a lot?).

like image 141
gct Avatar answered Feb 05 '23 20:02

gct