C++ 的库路径。失败?
我正在尝试在 Mac 上执行此代码。我已经安装了卷曲。当我搜索curl时,我可以在/usr/include/curl/curl.h
下找到它。下面是我想要运行的程序。取自此处。
#include <iostream>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
当我尝试编译程序时。见下文。
g++ simple.cpp
Undefined symbols:
"_curl_easy_perform", referenced from:
_main in cciFNPkt.o
"_curl_easy_init", referenced from:
_main in cciFNPkt.o
"_curl_easy_setopt", referenced from:
_main in cciFNPkt.o
"_curl_easy_cleanup", referenced from:
_main in cciFNPkt.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
这是怎么回事?为什么程序找不到该文件的路径?
我该如何修复它?
Im trying to execute this code on a mac. I have installed the curl. When i search for curl, i can find it under /usr/include/curl/curl.h
. Below is the program i want to run. Taken from here.
#include <iostream>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
when i try to compile the program. see below.
g++ simple.cpp
Undefined symbols:
"_curl_easy_perform", referenced from:
_main in cciFNPkt.o
"_curl_easy_init", referenced from:
_main in cciFNPkt.o
"_curl_easy_setopt", referenced from:
_main in cciFNPkt.o
"_curl_easy_cleanup", referenced from:
_main in cciFNPkt.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
What s going on? why doesnt the program finds the path of this file?
How can i fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记链接 libcurl 库:
像
这样的头文件(通常)仅声明一组函数存在,但不包含实际函数。对于 OS X Lion 上的curl,这些函数位于 libcurl 中(/usr/lib/libcurl.dylib,它指向 /usr/lib/libcurl.4.dylib)。您需要告诉链接器(通过编译器前端)该库的信息,这可以通过 -lcurl 来完成。You’ve forgotten to link the libcurl library:
A header file such as
<curl/curl.h>
(typically) only declares that a group of functions exist but does not contain the actual functions. In the case of curl on OS X Lion, those functions are in libcurl (/usr/lib/libcurl.dylib, which points to /usr/lib/libcurl.4.dylib). You need to tell the linker (via the compiler frontend) about that library, which can be done via-lcurl
.程序确实找到了包含文件,但没有找到库文件。
库文件应该类似于 libcurl.dylib 或 libcurl.a
使用它来链接它:
The program does find the include file but not the library file.
The library file should be something like libcurl.dylib or libcurl.a
Use this to link with it: