(C++) CURL_STATICLIB: 没有那个文件或目录

(C++) CURL_STATICLIB: No such file or directory

我已经安装并配置了我的 curl 库,并通过 CodeBlocks 将它链接到 MinGW。一切顺利,但是当我构建代码时,出现错误:

CURL_STATICLIB        No such file or directory

这是错误的屏幕截图: CURL_STATICLIB Error

我在#defines 中定义了 CURL_STATICLIB: CURL_STATICLIB in #defines

这里还有一个构建日志:

-------------- Build: Debug in CurlTest (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g CURL_STATICLIB -DCURL_STATICLIB -std=c++11 -lcurl -DCURL_STATICLIB -IC:\libs\curl\include -c C:\Users\ondre\OneDrive\Documents\Projects++\CurlTest\main.cpp -o obj\Debug\main.o
mingw32-g++.exe: error: CURL_STATICLIB: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

我的编译器信息:

MinGW gcc (GCC) 5.3.0

来自你失败的编译命令:

mingw32-g++.exe -Wall -fexceptions -g CURL_STATICLIB -DCURL_STATICLIB -std=c++11 \
-lcurl -DCURL_STATICLIB -IC:\libs\curl\include \
-c C:\Users\ondre\OneDrive\Documents\Projects++\CurlTest\main.cpp-o obj\Debug\main.o

我们可以看到,以及将 CURL_STATICLIB 添加到预处理器 定义 (-DCURL_STATICLIB),您实际上也已将其添加到您的 其他编译器选项 (-g CURL_STATICLIB)。当然因为 字符串 CURL_STATICLIB 不是 g++ 选项,也不是 以 - 开头,g++ 将其解释为输入文件的名称 对于编译,它解释了你的错误。

此外,您已将 -lcurl 添加到您的编译选项中, 表示您想要 link libcurl 与您的程序一起使用。这不是 一个编译选项,它是一个 linkage 选项。编译器会忽略它 而且,如果您还没有将它添加到您的 linker 选项中,那么您的 编译成功后,程序将无法 link。

要解决此问题,请从您的编译器选项中删除 -lcurl 并添加它 到 其他 linker 选项