如何将libcurl与linux中的c ++程序相链接? [英] How do I link libcurl to my c++ program in linux?

查看:141
本文介绍了如何将libcurl与linux中的c ++程序相链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我在ubuntu机器上编写的软件中使用libcurl。我正在使用Eclipse来编写和编译所有的软件。当我将libcurl文件放在与.cpp文件相同的文件夹中,并在标题中包含curl.h文件,当我尝试编译程序时,会出现这些错误:

I need to use libcurl in a piece of software I am writing on my ubuntu machine. I am using Eclipse to write and compile all of the software. When I put the libcurl files in the same folder as the .cpp file, and include the curl.h file in the header, When I attempt to compile the program, It comes up with these errors:

Building target: sms
Invoking: GCC C++ Linker
g++  -o"sms"  ./src/sms.o   
./src/sms.o: In function `main':
/home/geekman/workspace/sms/Debug/../src/sms.cpp:38: undefined reference to `curl_easy_init'
/home/geekman/workspace/sms/Debug/../src/sms.cpp:42: undefined reference to `curl_easy_setopt'
/home/geekman/workspace/sms/Debug/../src/sms.cpp:44: undefined reference to `curl_easy_setopt'
/home/geekman/workspace/sms/Debug/../src/sms.cpp:46: undefined reference to `curl_easy_perform'
/home/geekman/workspace/sms/Debug/../src/sms.cpp:47: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [sms] Error 1

我从libcurl中获取了include文件夹的内容,并将它们放在与.cpp文件相同的文件夹中。然后在.cpp文件的标题中键入:

I took the contents of the include folder from libcurl, and placed them in the same folder as the .cpp file. then in the header of the .cpp file, I typed:

#include <curl/curl.h>

我也尝试过:

#include "curl/curl.h"

有关问题的任何想法?谢谢。

Any ideas on the problem? Thanks.

推荐答案

你的头文件夹杂物很好您的问题出现在链接步骤。为了链接libcurl,您需要添加 -lcurl 命令行选项,假设它已安装在标准目录中:

Your header file inclusions are just fine; your problem is occurring at the linking step. In order to link against libcurl, you need to add the -lcurl command line option, assuming it's installed in a standard directory:

g++ -o sms ./src/sms.o -lcurl

如果没有安装在标准目录中,还需要将 -L / path /添加到/ libcurl ,例如如下所示:

If it's not installed in a standard directory, you also need to add the -L/path/to/libcurl, e.g. something like:

# Assuming that /home/geekman/workspace/libcurl is where libcurl.a is located
g++ -o sms ./src/sms.o -L/home/geekman/workspace/libcurl -lcurl

另请注意,

这篇关于如何将libcurl与linux中的c ++程序相链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆