I am trying to run a code in C++ that will automatically save a specified web page from the internet. I am using the Linux Mint Operating System, and my code is being written through CodeBlocks. The below is the code I am attempting to use:
Yes, I am running a Linux system and I read somewhere that this line must be inserted if it is Linux for the code to run. This may not be the case though.
Also note that when I removed it and ran the code again, I got the following additional errors:
In function ‘int main()’:
In function `main':
undefined reference to `curl_easy_init'
undefined reference to `curl_easy_setopt'
undefined reference to `curl_easy_perform'
undefined reference to `curl_easy_cleanup'
no. that has to be run to compile the code. it shouldnt be put in the code, unless its quoted or in a comment, or it will make an error. if you are writing a shell script or something like that then you need something like that
Your issue is not specific to curl: the order of arguments to gcc is important: compiler options, then source files, then object files, then libraries (from high-level to low-level); so try to compile with
gcc -Wall -g prog.c -lcurl -o binprog
or (for a C++ program)
g++ -Wall -g otherprog.cc -lcurl -o binotherprog
Of course you need the development package e.g. libcurl-dev or libcurl3-gnutls-dev or libcurl4-gnutls-dev (packaged in Ubuntu); on your CentOS distribution it might be called libcurl-devel or something else.
But the order in which the libraries are listed is important, as I have recenty learnt. The GCC linker will only check libraries, as it processes them left to right, for the dependencies that it already knows about.
PS I usually use Visual C++, whose linker puts a lot more effort into finding dependencies...
sorry yes library order can be important, like when compiling with sfml but i have compiled as $g++ foo.cpp -o bar and with $g++ -o bar -Wall -Wextra foo.cpp -o3 (<-- is that the optimization one? i havent had to use it in a while)
You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified. Also, the placement of the -l option is significant.