【发布时间】:2020-05-01 13:50:24
【问题描述】:
我必须制作一个 Linux 应用程序,该应用程序将从队列中打开网站并下载它们并将它们作为文件存储在我的 PC 上,同时使用线程。 我们有一个 web_request.c 和 web_request.h 类,它们使用 OPENSSL 和 CURL 来完成这项工作,我们可以使用 web_request.c 中的函数来下载我们排队的站点。 到目前为止,我一直在尝试在 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
curl-config --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
【问题讨论】:
-
可能相关? >> (.text+0x20): 对 `main' 的未定义引用