[英]Library path for C++. Fail?
Im trying to execute this code on a mac. 我试图在mac上执行此代码。 I have installed the curl. 我已经安装了卷发。 When i search for curl, i can find it under /usr/include/curl/curl.h
. 当我搜索curl时,我可以在/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? 我该如何解决?
You've forgotten to link the libcurl library: 您忘记链接libcurl库:
g++ simple.cpp -lcurl
A header file such as <curl/curl.h>
(typically) only declares that a group of functions exist but does not contain the actual functions. 诸如<curl/curl.h>
类的头文件(通常)仅声明存在一组函数但不包含实际函数。 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). 对于OS X Lion上的curl,这些函数位于libcurl中(/usr/lib/libcurl.dylib,它指向/usr/lib/libcurl.4.dylib)。 You need to tell the linker (via the compiler frontend) about that library, which can be done via -lcurl
. 您需要告诉链接器(通过编译器前端)关于该库,可以通过-lcurl
完成。
The program does find the include file but not the library file. 该程序确实找到了包含文件,但没有找到库文件。
The library file should be something like libcurl.dylib or libcurl.a 库文件应该类似于libcurl.dylib或libcurl.a
Use this to link with it: 用它来链接它:
g++ simple.cpp -lcurl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.