CMake linking against shared library on windows: error about not finding .lib file(CMake 链接到 Windows 上的共享库:关于找不到 .lib 文件的错误)
问题描述
我在 CMake 中有一个库定义,它构建了一个共享库一小部分文件,我已经在 linux 和 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.
但是,我还有另一个库链接到共享库,它在 linux 上运行良好,但是,在 Windows 上我收到一条消息,或者错误找不到 Release/nnet.lib"链接时间.有什么特别的我必须做才能做到这一点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?
编辑,例如:
主共享库(更改文件名以保护无辜者):
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)
然后我正在构建一个链接库中的 python 模块:
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})
其余的只是样板文件(例如:在 Windows 上将模块扩展名更改为 .pyd,查找 python 库/头文件等)然后在 VS 2008 中构建时,我得到:
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:
致命错误 LNK1181:无法打开输入文件'发布 net.lib'
fatal error LNK1181: cannot open input file 'Release net.lib'
构建 other_lib 时.请注意,在构建 nnet 时不会抛出任何错误.
when building other_lib. Note no errors are thrown while building nnet.
推荐答案
啊,我的问题是我在构建库时忘记在合适的地方包含一个 __declspec(dllexport)(你能告诉我我不做 windows 编程吗?很多?).
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 文件的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 链接到 Windows 上的共享库:关于找不到 .lib 文件的错误
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07