C语言 使用 CMake 生成 .dll

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6499364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 09:00:51  来源:igfitidea点击:

Generating .dll using CMake

cwindowsdllcmake

提问by javaMan

I have the following C files in windows XP. optBladWriter.c optWriteNlpEmpsFile.c I would like to generate DLL for this code. I used the command add_library . My make file has the following :

我在 Windows XP 中有以下 C 文件。optBladWriter.c optWriteNlpEmpsFile.c 我想为此代码生成 DLL。我使用了命令 add_library 。我的制作文件有以下内容:

CMAKE_MINIMUM_REQUIRED ( VERSION 2.6)
add_library (optFmg optBladWriter.c optWriteNlpEmpsFile.c) 

after running CMake using command prompt Project.sln is created. I imported it to the visual studio and built it. I got the optFmg.lib file. But I want the optFmg.dll file.

使用命令提示符运行 CMake 后,创建了 Project.sln。我将它导入到视觉工作室并构建它。我得到了 optFmg.lib 文件。但我想要 optFmg.dll 文件。

Can u help me in generating the dll file using cmake in the above case. Is there any particular command similar to add_library.

你能帮我在上述情况下使用 cmake 生成 dll 文件吗?是否有任何类似于 add_library 的特定命令。

Thanks

谢谢

回答by bdonlan

As documented, the default type of library is determined by the BUILD_SHARED_LIBSvariable. You can explicitly request a shared library with:

如文档所述,库的默认类型由BUILD_SHARED_LIBS变量决定。您可以通过以下方式显式请求共享库:

add_library(yourlib SHARED file.c ...)