如何让 CMake 创建 dll 及其匹配的 lib 文件?
我正在使用 CMake 通过 Visual Studio 2010 创建共享库。该解决方案输出一个 dll 文件,但不是匹配的 lib 文件。如何告诉 CMake 生成 lib 文件,以便我可以将其他项目链接到 dll?
I'm using CMake to create a shared library via Visual Studio 2010. The solution outputs a dll file, but not a matching lib file. How do I tell CMake to generate the lib file so I can link other projects to the dll?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先检查共享库中是否至少有一个导出的符号。如果 dll 不导出符号,Visual Studio 不会生成
.lib
文件。接下来,检查您的 cmake 文件 - 可能您已经设置了共享库目标的
CMAKE_ARCHIVE_OUTPUT_DIRECTORY
变量或ARCHIVE_OUTPUT_DIRECTORY
属性。如果设置了这些变量/属性,则 Visual Studio 会将.lib
文件输出到该变量/属性指定的不同目录中。 (还可以有特定于配置的版本,例如 ARCHIVE_OUTPUT_DIRECTORY_Release。)First of all check that you have at least one exported symbol in your shared library. Visual Studio does not generate the
.lib
file if dll does not exports symbols.Next, check your cmake files - probably you have set
CMAKE_ARCHIVE_OUTPUT_DIRECTORY
variable orARCHIVE_OUTPUT_DIRECTORY
property of the shared library target. If these variable/property is set then Visual Studio will output.lib
files into the different directory specified by that variable/property. (There also can be configuration-specific versions likeARCHIVE_OUTPUT_DIRECTORY_Release
.)将此命令添加到您的 CMakeLists.txt
设置(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add this command to your CMakeLists.txt
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)