如何使用libcurl作为cmake的静态库?

时间:2015-12-25 17:27:22

标签: c++ cmake libcurl

我已经用Google搜索了,无法解决这个问题。我正在努力学习c ++。但我的项目需要libcurl才能工作。

现在我无法通过谷歌搜索这个问题来弄清楚如何使用cmake将libcurl库与我的项目静态链接。我正在开发Windows 10 64位。

我相信我遗漏了很多关于c ++中的所有内容如何与库一起工作的想法。我可以找到一些答案,部分回答我的问题,但没有什么可以拼凑在一起。如果有一些答案可以回答我的问题,我会非常乐意将这些答案提供给我。

下面是我的代码,cmakelists&我目前的错误。

#include <iostream>
#include <sstream>
#include <curl.h>

int main() {

std::string username;
std::string password;

std::cout << "Please enter the username of the account you want to use to snipe" << std::endl;
std::cin >> username;

std::cout << "Please enter the password of the account you want to use to snipe" << std::endl;
std::cin >> password;

curl_global_init(CURL_GLOBAL_ALL);

}

CMakeLists:

cmake_minimum_required(VERSION 3.3)
project(Learning)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories(curl/include/curl)
link_directories(curl/bin)

set(SOURCE_FILES main.cpp)
add_executable(Learning ${SOURCE_FILES})
target_link_libraries(Learning curl)

错误:

"C:\Program Files (x86)\JetBrains\CLion 1.2.2\bin\cmake\bin\cmake.exe" --build C:\Users\Czarek\.CLion12\system\cmake\generated\c124b936\c124b936\Debug --target Learning -- -j 8
Scanning dependencies of target Learning
[ 50%] Building CXX object CMakeFiles/Learning.dir/main.cpp.obj
[100%] Linking CXX executable Learning.exe
CMakeFiles\Learning.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Czarek/ClionProjects/Learning/main.cpp:16: undefined reference to `curl_global_init'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Learning.exe] Error 1
CMakeFiles\Learning.dir\build.make:96: recipe for target 'Learning.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Learning.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Learning.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Learning.dir/rule] Error 2
mingw32-make.exe: *** [Learning] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Learning.dir/rule' failed
Makefile:117: recipe for target 'Learning' failed

0 个答案:

没有答案