簡體   English   中英

如何在 CLION 中將 curl(libcurl) 添加到我的 C 項目中?

[英]how do I add curl(libcurl) to my C project in CLION?

我必須制作一個 Linux 應用程序,該應用程序將從隊列中打開網站並下載它們並將它們作為文件存儲在我的 PC 上,同時使用線程。 We got a web_request.c and web_request.h class that uses OPENSSL and CURL for the job, we may use the functions from web_request.c to download the sites we got lined up on our queue. 我一直在嘗試在 curl 之后編譯,但到目前為止沒有成功,絕對可以使用一些幫助。

我的 CMakeLists.txt:

project(BS06 C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS -lm -lssl -lcrypto -pthread -lcurl)

add_executable(BS06 main.c)

我如何在 main.c 上包含 web_request.h 以使用它們的功能:

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <values.h>
#include <string.h>
#include "include/web_request.h"

我如何在 web_Request.c 中包含 curl

#include "web_request.h"
#include <assert.h>
#include <curl/curl.h>
#include <getopt.h>
#include <openssl/opensslv.h> // OPENSSL_VERSION_NUMBER
#include <stdio.h>
#include <string.h> // strncmp

CURL --版本:

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24 

卷曲配置--libs:

-lcurl

錯誤:

 [50%] Building C object CMakeFiles/BS06.dir/main.c.o
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
/bin/sh: 1: -lssl: not found
/bin/sh: 1: -lcrypto: not found
/bin/sh: 1: -pthread: not found
/bin/sh: 1: -lcurl: not found
CMakeFiles/BS06.dir/build.make:62: recipe for target 'CMakeFiles/BS06.dir/main.c.o' failed
make[3]: *** [CMakeFiles/BS06.dir/main.c.o] Error 127
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/BS06.dir/all' failed
make[2]: *** [CMakeFiles/BS06.dir/all] Error 2
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/BS06.dir/rule' failed
make[1]: *** [CMakeFiles/BS06.dir/rule] Error 2
Makefile:118: recipe for target 'BS06' failed
make: *** [BS06] Error 2

看來您需要將 curl 庫與可執行文件鏈接起來。 如果你重寫你的 CMakeList.txt 有幫助嗎:

project(BS06 C)

set(CMAKE_C_STANDARD 11)
find_package(CURL REQUIRED) 

include_directories(${CURL_INCLUDE_DIR})
add_executable(BS06 main.c)
target_link_libraries(BS06 ${CURL_LIBRARIES})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM