Netbeans 中的 libcurl:'undefined reference to...'
libcurl in Netbeans: 'undefined reference to...'
我现在已经尝试了几天在Windows机器上运行Netbeans(编译器是cygwin)的libcurl示例c++代码,但每次都失败。我也通过网络(也通过stackoverflow)搜索过,但找不到解决方案……(
这是我想运行的示例代码…
#include <cstdlib>
#include <curl/curl.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
下面是编译结果:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x_1-Windows/cppapplication_3.exe
make[2]: Entering directory `/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3'
mkdir -p build/Debug/Cygwin_4.x_1-Windows
rm -f build/Debug/Cygwin_4.x_1-Windows/main.o.d
g++.exe -lcurl -c -g -MMD -MP -MF build/Debug/Cygwin_4.x_1-Windows/main.o.d -o build/Debug/Cygwin_4.x_1-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin_4.x_1-Windows
g++.exe -lcurl -o dist/Debug/Cygwin_4.x_1-Windows/cppapplication_3 build/Debug/Cygwin_4.x_1-Windows/main.o
build/Debug/Cygwin_4.x_1-Windows/main.o: In function `main':
/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3/main.cpp:20: undefined reference to `_curl_easy_init'
/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3/main.cpp:22: undefined reference to `_curl_easy_setopt'
/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3/main.cpp:23: undefined reference to `_curl_easy_perform'
/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3nbproject/Makefile-Debug.mk:61: recipe for target `dist/Debug/Cygwin_4.x_1-Windows/cppapplication_3.exe' failed
make[2]: Leaving directory `/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/Alexander/Documents/NetBeansProjects/CppApplication_3'
/main.cpp:25: undefined reference to `_curl_easy_cleanup'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin_4.x_1-Windows/cppapplication_3.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
libcurl也作为一个包安装在cygwin中…libcurl。a位于"E:cygwinlib",cygcurl-4.dll位于"E:cygwinbin"。
如果有人能帮我,那就太好了!提前感谢!问候,亚历克斯
将-l
选项放在链接命令的末尾,如下所示:
g++ -o main main.o -lcurl
那么在你的例子中输出应该是这样的:
g++.exe -o dist/Debug/Cygwin_4.x_1-Windows/cppapplication_3 build/Debug/Cygwin_4.x_1-Windows/main.o -lcurl
来自gcc手册:
在命令中写入[-l]选项会产生影响;的链接器按顺序搜索和处理库和目标文件它们是指定的。因此,
foo.o -lz bar.o' searches library
z′后文件foo。但是在酒吧之前。如果酒吧。O表示z中的函数,这些函数不能被加载。
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 为什么创建友元类的实例会导致"undefined reference to"错误?
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- OpenCV undefined reference to 'cv::imread(cv::String const&, int)'
- Libcurl c++ "undefined reference to" (Windows/MinGW/g++)
- 尝试使用 extern "C" 调用 C 中的C++方法,得到"undefined reference to"对象的链接器错误
- build error : undefined reference to `yyFlexLexer::yyFlexLex
- 声明和定义函数静态会产生"undefined reference to function_name()"
- Cppcheck "Reference to auto variable returned"失败的原因?
- C++ : "undefined reference to"可能是因为CMake文件
- 索引 2D 向量时'Reference to type const..'编译错误
- 为什么我收到以下错误:"returning reference to temporary [-Werror=return-local-addr]"
- AppData\Local\Temp\cc59LXDc.o:test1.cpp: undefined reference to 'constructNewObjectOfClass
- YAML-cpp 编译错误:"undefined reference to YAML::LoadFile"
- 添加 cpp11 插件时出现错误消息"Undefined reference to boost (...)"
- 如果我将"reference to vector"分配给"vector"会发生什么情况
- 获得"undefined reference to"