如何在我的C项目中的代码块(Windows)中包含curl库? [英] How do I include curl library in my C project in Code Blocks (Windows)?

查看:306
本文介绍了如何在我的C项目中的代码块(Windows)中包含curl库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎很简单。我尝试了很多东西,只是为了包括curl在我的C项目使用代码:: blocks ide但没有效果。

The question seems straight forward. I tried a lot of things just to include curl in my C project using the code::blocks ide but to no avail.

我想使用cURL的库控制台应用程序需要http功能。
如果任何人已经成功这样做,那么你的帮助是非常感谢。 :)

I would like to use cURL's library for my console app project that needs http capabilities. If anyone had successfully done so, then your help is very much appreciated. :)

之前发生了什么:

- 我将所有cURL文件复制到我的项目,具有.a或.lib ext的那些。)

-I copied all cURL files to my project and linked the libraries (the ones with .a or .lib ext.)

- 当我构建项目时。很多未定义的引用出现了。

-Then when I build the project. A lot of undefined reference showed up.

这是我测试的代码:

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

    int main()
    {
     curl_global_init( CURL_GLOBAL_ALL );
     CURL * myHandle;
     CURLcode result; 
     myHandle = curl_easy_init ( ) ;

     curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.example.com");
     result = curl_easy_perform( myHandle );
     curl_easy_cleanup( myHandle ); 
     printf("LibCurl rules!\n");
     return 0;
    }

以下是错误:

||=== Fa, Release ===|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_global_init'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_init'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_setopt'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_perform'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_cleanup'|
||=== Build finished: 5 errors, 0 warnings ===|


推荐答案

转到您的项目Build Options链接器选项卡,因此您有两个选择:

Go to your project "Build Options" -> "Linker" tab and so you have two choices:


  1. 如果您的库已正确安装在系统范围,其他链接器选项的lib,就像你直接使用你的编译器。
    对于GCC,您可以写 -lcurl 。您还可以使用此路径指令,如 wl,-rpath,/ path / to / your / library -lMyLib 。显然,这取决于编译器和系统设置。

  1. If your library is (correctly) installed system-wide, write in "other linker options" the libs as if you were using your compiler directly. For GCC you'd write -lcurl. You may also use this with a path instruction like Wl,-rpath,/path/to/your/library -lMyLib. Obviously it depends on the compiler and system setup.

将库添加到左侧的链接库点击添加按钮并浏览到您的图书馆文件。

Add the library in "Link libraries" on the left. Click the "Add" button and browse to your library file.

http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/rel =nofollow> A.3 - 对于某些图片使用带有Code :: Blocks的库。
Googling会显示更多信息。

Take a look at this A.3 — Using libraries with Code::Blocks for some pictures. Googling around will show you more.

这篇关于如何在我的C项目中的代码块(Windows)中包含curl库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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