CMake 链接到 Windows 上的共享库:关于找不到 .lib 文件的错误

CMake linking against shared library on windows: error about not finding .lib file(CMake 链接到 Windows 上的共享库:关于找不到 .lib 文件的错误)

本文介绍了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 文件的错误