12

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.

1 Answer 1

14

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

Sign up to request clarification or add additional context in comments.

2 Comments

On windows no .lib import library file is generated if no symbols are exported. You need at least one dllexport for the file to be created. I have beaten my head against this before.
Alternatively, you can also put a set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) into your CMakeLists.txt and then all symbols will be exported without needing __declspec(dllexport).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.