简体   繁体   中英

How do I prepare or compile a third party library cloned from github so I can reference it in my program?

I am trying to use a third party library in my C program, in this particular case the library is curl.

My folder structure is as follows:

Root
    -curl
    -main.c

The curl folder the cloned Curl repo from github.

My main.c file has the appropriate header file included, as mentioned in curl docs.

How do I compile, link or prepare the curl folder that I cloned so I can use it in my project?

Follow the curl documentation to compile curl into a static or shared library.

If you install the compiled curl library into your system, then you just compile your main program and link against curl: -lcurl. Your compiler will find curl installed In the system, and also find the include folder In the system automatically.

If you didnt want to install curl into the system, then install it into your projects directory under a "deps/curl" then link against the file in that local folder, and add the include folder path when compiling. For example, linking against the static lib in your local application folder.

gcc -o app -I ./deps/curl/include -l ./deps/curl/lib/curl.a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM