2017-08-23 8 views
0

libcurlを使ってC++プログラムにWebソースを読み込ませたいのですが、 "curl.h"というファイルを開くことはできません。あなたはカールソースを含めましたと仮定すると、カールライブラリは独立して、あなたはおそらく、二重引用符を探しているインストールされている場所で、ヘッダーを検索するために、コンパイラに指示してきた場合を除きlibcurlをC++プロジェクトにインポートするには?

image

+0

ビジュアルスタジオを使用していますか? – user3808887

+4

https://curl.haxx.se/libcurl/c/libcurl-tutorial.html、特に「プログラムのコンパイル」を参照してください。 – racraman

答えて

1

。それ以外の場合は、プロジェクト設定でパスをインクルードする必要があります。

What is the difference between #include <filename> and #include "filename"?

違いは、プリプロセッサが含まれるファイルを検索する場所です。

#include "filename"の場合、プリプロセッサはディレクティブを含むファイルと同じディレクトリで検索し、#includeのようにします。このメソッドは通常、プログラマー定義のヘッダーファイルを含めるために使用されます。

#includeの場合、ファイル名>プリプロセッサは、通常、コンパイラ/ IDEによってあらかじめ指定された検索ディレクトリ内で、実装に依存した方法で検索します。このメソッドは通常、標準ライブラリヘッダーファイルをインクルードするために使用されます。

0
In short, 
Add the path of the libcurl's include folder in C/C++ -? General -> Additional include directories. This way the Visual Studio will get to know the location of curl.h 

In Detail: 
Using libcurl involves 2 steps: 
1. Download and build libcurl on your platform. 
2. Plug-it in your C\C++ application 

Step 1: 
Download code from https://curl.haxx.se/download.html and unzip the zip file in a folder. I guess you already have done it. 
cd curl-src\winbuild 
nmake /f Makefile.vc mode=<static or dll> <options> 
VC=<6,7,8,9,10,11,12,14>  - VC versions 
    WITH_DEVEL=<path>   - Paths for the development files (SSL, zlib, etc.) 
           Defaults to sibbling directory deps: ../deps 
           Libraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/ 
           Uncompress them into the deps folder. 
    WITH_SSL=<dll or static>  - Enable OpenSSL support, DLL or static 
    WITH_MBEDTLS=<dll or static> - Enable mbedTLS support, DLL or static 
    WITH_CARES=<dll or static> - Enable c-ares support, DLL or static 
    WITH_ZLIB=<dll or static> - Enable zlib support, DLL or static 
    WITH_SSH2=<dll or static> - Enable libSSH2 support, DLL or static 
    ENABLE_SSPI=<yes or no>  - Enable SSPI support, defaults to yes 
    ENABLE_IPV6=<yes or no>  - Enable IPv6, defaults to yes 
    ENABLE_IDN=<yes or no>  - Enable use of Windows IDN APIs, defaults to yes 
           Requires Windows Vista or later, or installation from: 
           https://www.microsoft.com/downloads/details.aspx?FamilyID=AD6158D7-DDBA-416A-9109-07607425A815 
    ENABLE_WINSSL=<yes or no> - Enable native Windows SSL support, defaults to yes 
    GEN_PDB=<yes or no>   - Generate Program Database (debug symbols for release build) 
    DEBUG=<yes or no>   - Debug builds 
    MACHINE=<x86 or x64>   - Target architecture (default is x86) 

For More info, you can read INSTALL file present in the downloaded zip. 

Step 2: Once you have the library built, plug-it in you application as: 
a) Right Click the VS project in which you want to add the dependency of curl and select properties. 
b) Add the path of the libcurl's include folder in C/C++ -> General -> Additional include directories. This way the Visual Studio will get to know the location of curl.h 
c) Add the path of libcurl library in linker -> General -> Additional Library Directories. 
d) Mention libcurl name in Linker -> input -> Additional Dependencies. 

You are good to go ! 
Note: if you are using dll for curl, then this dll should be present in the same directory in which your .exe for the application is present. 
関連する問題