CMake链接共享库在Windows上:关于没有找到.lib文件的错误 [英] CMake linking against shared library on windows: error about not finding .lib file

查看:1893
本文介绍了CMake链接共享库在Windows上:关于没有找到.lib文件的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在CMake的库定义建立一个共享库出
的一小组文件,我已经编译只是罚款在linux和windows。



然而,我还有另一个库链接到共享库,它在Linux上正常工作,但是,在Windows我得到一条消息沿线或错误找不到发布/nnet.lib。有什么特别的,我要做到这一点,在Windows上的
链接?



编辑,例如:


$ b b

主共享库(更改了文件名以保护无辜者):

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

然后我正在构建一个链接到库中的python模块:

 构建python模块
ADD_LIBRARY(other_lib SHARED $ {CMAKE_SOURCE_DIR} /src/boost/boost_main.cc)
TARGET_LINK_LIBRARIES(other_lib nnet $ {PYTHON_LIBRARIES})
pre>

其余的只是样板文件(例如:改变模块扩展到.pyd的窗口,查找python库/标头等)
然后当建VS 2008我得到:


致命错误LNK1181:无法打开输入
文件'Release\\\
net.lib'


。建立nnet时不会抛出任何错误。

解决方案

啊,我的问题是我忘了在适当的时候加入__declspec建立图书馆的地方(你能告诉我不要做Windows编程吗?)。


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.

解决方案

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

这篇关于CMake链接共享库在Windows上:关于没有找到.lib文件的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆