How do I link dynamically built cmake files on Windows?

怎甘沉沦 提交于 2019-12-11 05:17:09

问题


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.

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

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.

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)

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


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/58904952/how-do-i-link-dynamically-built-cmake-files-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!