简体   繁体   English

libcurl与mingw和clion的链接

[英]libcurl link with mingw and clion

I'm trying to build my project using curl, but I have this result : undefined reference to `_imp__curl_easy_init' 我正在尝试使用curl构建我的项目,但是我有这个结果:未定义引用`_imp__curl_easy_init'

This is my CMakeLists : 这是我的CMakeLists:

cmake_minimum_required(VERSION 2.8)
project(score)

set(SOURCE_FILES main.cpp)
add_executable(score ${SOURCE_FILES})

add_library(libcurl STATIC IMPORTED)
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION "c:/MinGW/lib")

SET(GCC_COVERAGE_LINK_FLAGS    "-lcurl")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS}    ${GCC_COVERAGE_LINK_FLAGS}" )

Moreover, I put my file libcurl.a, etc... in the correct directory "c:/MinGW/lib". 而且,我将我的文件libcurl.a等放在正确的目录“c:/ MinGW / lib”中。

Could you help me ? 你可以帮帮我吗 ?

You probably need to compile the source files that call the curl functions with the CURL_STATICLIB macro defined. 您可能需要编译调用curl函数的源文件,并定义CURL_STATICLIB宏。

Do you have access to the curl-config utility? 你有权访问curl-config实用程序吗? It's there when you build curl from source. 当你从源代码构建curl时它就在那里。 Run it with the --cflags option to get the compiler flags required and the --libs option to get linker requirements. 使用--cflags选项运行它以获取所需的编译器标志,使用--libs选项获取链接器要求。

For example, in my mingw environment, the cflags reported are -DCURL_STATICLIB -I/mingw/local/include and the lib flags reported are -L/mingw/local/lib -lcurl -lssl -lcrypto -lgdi32 -lwldap32 -lz -lws2_32 . 例如,在我的mingw环境中,报告的cflags是-DCURL_STATICLIB -I/mingw/local/include ,报告的lib标志是-L/mingw/local/lib -lcurl -lssl -lcrypto -lgdi32 -lwldap32 -lz -lws2_32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM