0

I'm trying to compile the following in code:blocks as a C++ project

                #include <curl/curl.h>

                int main(void)
                {
                        char * result;
                        CURL *curl;
                        CURLcode res;
                        curl = curl_easy_init();
                        if(curl) {
                            curl_easy_setopt(curl, CURLOPT_URL, "http://google.com/");

                            res = curl_easy_perform(curl);
                            curl_easy_cleanup(curl);
                        }
                        return 0;
                 }

I set my linker as so: http://puu.sh/peeYr/9cb79897e5.png

And all i get this this massive spam of errors.

                ||=== Clean: Debug in nettest (compiler: GNU GCC Compiler) ===|
                ||=== Build: Debug in nettest (compiler: GNU GCC Compiler) ===|
                U:\Main\Code\nettest\main.cpp||In function 'int main()':|
                U:\Main\Code\nettest\main.cpp|5|warning: unused variable 'result' [-Wunused-variable]|
                U:\Main\Code\nettest\main.cpp|7|warning: variable 'res' set but not used [-Wunused-but-set-variable]|
                U:\Main\Code\Libs\curl\lib\libcurl.a(easy.o)|| undefined reference to `WSAStartup@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(easy.o)|| undefined reference to `WSACleanup@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(easy.o)|| undefined reference to `WSACleanup@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `WSASetLastError@4'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `select@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| more undefined references to `__WSAFDIsSet@8' follow|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `select@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(select.o)|| undefined reference to `__WSAFDIsSet@8'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(asyn-thread.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(url.o):(.text.unlikely+0x265)||undefined reference to `idna_to_ascii_lz'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(url.o):(.text.unlikely+0x26c)||undefined reference to `stringprep_locale_charset'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(url.o):(.text.unlikely+0x2d8)||undefined reference to `idna_to_unicode_lzlz'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(url.o):(.text.unlikely+0x2fc)||undefined reference to `tld_check_lz'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(url.o):(.text.unlikely+0x382)||undefined reference to `stringprep_check_version'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `recv@16'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `recv@16'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `send@16'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(sendf.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `getsockopt@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `ntohs@4'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `getpeername@12'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `getsockname@12'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `getsockopt@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `setsockopt@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `recv@16'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `closesocket@4'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `socket@12'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `setsockopt@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAIoctl@36'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAGetLastError@0'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `bind@12'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `ntohs@4'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `htons@4'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `setsockopt@20'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `getsockname@12'|
                U:\Main\Code\Libs\curl\lib\libcurl.a(connect.o)|| undefined reference to `WSAGetLastError@0'|
                ||More errors follow but not being shown.|
                ||Edit the max errors limit in compiler options...|
                ||=== Build failed: 50 error(s), 2 warning(s) (0 minute(s), 3 second(s)) ===|

I then tried linking with the libcurldll.a and then the libcurl.dll from the bin folder, which compiled however when it came to running it said that "Libcurl.dll is missing from your computer".

I've downloaded the http://curl.haxx.se/dlwiz/?type=lib&os=Win32&flav=-

and am using the following compiler. http://puu.sh/pefvQ/0ed7876316.png

This is very annoying, and i can't work out why there is no documentation with this library especially as issues like this seem rampent. (i've tried the solutions of several SO questions such as Unresolved symbols when linking a program using libcurl

and

Adding static libcurl to Code::Blocks IDE ) However to no avail. How can i rectify this? Or is there a simpler, and better documented library i can use instead? As all i wish to do is perform an HTTP get request.

Community
  • 1
  • 1
user3407675
  • 107
  • 1
  • 7
  • Looks like you forgot to add `ws2_32` or similar to the libraries. Curl pulls in curl, but curl needs the winsock library for your version of windows. – user4581301 Jun 02 '16 at 18:11
  • I don't believe i have them currently. How would i get/link them into my project? – user3407675 Jun 02 '16 at 18:30
  • with winsock DLLs come stock with windows. The .a files you provide to the linker should be included in mingw. Add `ws2_32` to the dialog in http://puu.sh/peeYr/9cb79897e5.png. I'm not sure how Code::blocks orders the libraries, so I don't know if ws2_32` needs to be in that list before or after the curl libraries. – user4581301 Jun 02 '16 at 18:40
  • It seems it needs to be after. So like this? http://puu.sh/pektg/2cf79131b0.png as i now get a different collection of errors http://puu.sh/pekCy/959f84fbd6.png – user3407675 Jun 02 '16 at 19:06
  • ldap I've never had to pull into a project. Google says you want `wldap32`. http://stackoverflow.com/questions/7089704/how-to-statically-link-libcurl-with-dev-c confirms. Now you are likely in a mire of finding and adding libraries until you run out linker errors. Some help can be found here: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – user4581301 Jun 02 '16 at 19:11
  • Ight, thanks. Now i got a new load. http://puu.sh/pexFi/9bf75beafa.png No idea what these would even refer too. Do you know if there is a simpler/easier set of libraries to setup? (I wish to avoid dependencies) – user3407675 Jun 02 '16 at 22:00
  • You're deep in googlespace for me here. Googling "undefined reference to RTMP" pops up a load of pages. One recommends adding rtmp to the libraries list. Suggest you do similar for the remaining errors after this one is resolved – user4581301 Jun 02 '16 at 22:19

1 Answers1

0

I then tried linking with the libcurldll.a and then the libcurl.dll from the bin folder, which compiled however when it came to running it said that "Libcurl.dll is missing from your computer".

Stick with libcurl.dll.

You have successfully linked the program with libcurl.dll because your linker configuration (in Code::Blocks) successfully allowed the linker to find it.

libcurl.dll is a dynamic link library. That means the linker does not physically incorporate it into your program but just checks that it defines the functions or other symbols that your program tries to refer to within it, and inserts in your program a request to the Windows program loader to load the DLL at runtime. (This way, there needs only to be one copy of libcurl in the system that all curl client programs can potentially use).

This means that at runtime that DLL has got to exist in one of the places where the Windows loader looks for it, or Windows will say Libcurl.dll is missing from your computer

The places where Windows searches for DLLs are described here, from which you will see that the easiest way to get your program to run is to place libcurl.dll in the same directory with your .exe; although if you want to make it available to any curl-clients on your system, you'd go for option 3, 4 or 5.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182