How do I link libcurl to my c++ program in linux? How do I link libcurl to my c++ program in linux? linux linux

How do I link libcurl to my c++ program in linux?


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

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 locatedg++ -o sms ./src/sms.o -L/home/geekman/workspace/libcurl -lcurl

Also note that the -lcurl option has to appear after the list of object files you're linking, otherwise it won't link properly.


You can try to use curl-config --libs.


An alternate answer (the first one is excellent). Consider using the output returned by "pkg-config --libs libcurl" as an argument to your compiler.

For example,

CPPFLAGS=`pkg-config --libs libcurl`

g++ $CPPFLAGS myfile.o

Pkg-config is a standard way for open source libraries to communicate to you how to link against them / #include their files.