如何在Windows上链接动态生成的cmake文件? [英] How do I link dynamically built cmake files on Windows?

查看:166
本文介绍了如何在Windows上链接动态生成的cmake文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去8个小时,我一直在努力寻找有关如何在使用CMake构建的Windows上的C项目(尤其是cURL)中引用库的信息.

I have been struggling for the last 8 hours to find information on how to reference a library in a C project on Windows built with CMake, specifically cURL.

我已经从网站上下载了7.67版本的cURL源,然后使用Visual Studio开发人员命令提示符使用以下标准方法将CMake项目编译为一个构建文件夹:

I have downloaded version 7.67 cURL source from the website, and then went used the visual studio developer command prompt to compile the CMake project into a build folder using the standard method of:

cd winbuild
nmake /f Makefile.vc mode=dll

哪个输出三个curl文件夹,其中一个名为"libcurl-vc-x86-release-dll-ipv6-sspi-winssl". 在该文件夹中包含一个lib,一个bin和一个include文件夹.

Which outputs three curl folders, one of them called "libcurl-vc-x86-release-dll-ipv6-sspi-winssl". In that folder contains a lib, a bin, and an include folder.

我用CLion构建了C项目,这是生成的CMake文件.

I built my C project with CLion and this is the CMake file that is generated.

cmake_minimum_required(VERSION 3.15)
project(hello_world C)

set(CMAKE_C_STANDARD 99)

add_executable(hello_world main.c)

如何在带有CMake的C项目中正确使用编译的CURL?

How do I use my compiled CURL in my C project with CMake properly?

推荐答案

我终于解决了这个问题,方法是在C:目录中创建一个cmake文件夹,然后将其复制到内置的curl CMake项目文件夹中.

I finally solved this issue by creating a cmake folder at the C: directory, and copying in the built curl CMake project folder.

问题是我没有找到有关如何在Windows上为CMake引用项目的特定教程,特别是curl项目.

The issue was that there weren't any specific tutorials that I found on how to reference projects on Windows for CMake, specifically the curl project.

幸运的是,我发现这篇文章指出了我在分别引用include文件夹和.lib目录时遇到的问题. 如何在Windows中将共享库* dll与CMake链接

Fortunately, I found this post which specified an issue I had in referencing the include folder and .lib directory separately. How to link shared library *dll with CMake in Windows

cmake_minimum_required(VERSION 3.15)
project(hello_world C)

set(CMAKE_C_STANDARD 99)

include_directories("C:/cmake/libcurl-vc-x86-release-dll-ipv6-sspi-winssl/include")
link_directories("C:/cmake/libcurl-vc-x86-release-dll-ipv6-sspi-winssl/lib")

add_executable(hello_world main.c)

set( LIBS libcurl )
target_link_libraries(hello_world ${LIBS} )

现在,代码可以编译并成功运行. 我不认为这是执行此操作的正确方法,我们将不胜感激.

Now the code compiles and runs succesfully. I don't believe this is the proper method of doing this though, any help would be appreciated.

这篇关于如何在Windows上链接动态生成的cmake文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆