如何让 CMake 创建一个 dll 及其匹配的 lib 文件?

2023-08-27C/C++开发问题
0

本文介绍了如何让 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?

推荐答案

首先检查您的共享库中是否至少有一个导出的符号.如果 dll 不导出符号,Visual Studio 不会生成 .lib 文件.

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.

接下来,检查您的 cmake 文件 - 您可能已经设置了共享库目标的 CMAKE_ARCHIVE_OUTPUT_DIRECTORY 变量或 ARCHIVE_OUTPUT_DIRECTORY 属性.如果设置了这些变量/属性,则 Visual Studio 会将 .lib 文件输出到该变量/属性指定的不同目录中.(也可以有特定于配置的版本,例如 ARCHIVE_OUTPUT_DIRECTORY_Release.)

Next, check your cmake files - probably you have set CMAKE_ARCHIVE_OUTPUT_DIRECTORY variable or ARCHIVE_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 like ARCHIVE_OUTPUT_DIRECTORY_Release.)

这篇关于如何让 CMake 创建一个 dll 及其匹配的 lib 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6