cURL / Mailing Lists / curl-library / Single Mail


Linker errors in pre-compiled static library for windows

From: Garrick Mason <>
Date: Wed, 21 Aug 2013 21:24:10 -0400

My situation is actually very similar to the following:
though I can add some more details.

I'm trying to make a program in C++ that is statically linked to a
libcurl library to make a simple HTTP request but currently I'm unable
to even initialize curl in my program. My operating system is Windows 7
and I'm using the default Codeblocks install to create my program, so
I'm using g++ to compile my program. The package I'm working with is the
libcurl type package provided by GŁnter Knauf in the "Win32 - Generic"
section of the curl downloads page; version 7.32.0. Under the "Search
directories" section of the global compiler settings menu in Codeblocks,
I've added the include directory from the package to the Compiler
section of Codeblocks and in the Linker section I've added the lib
directory. Whenever I try to compile my program, I get these two errors
(for the test program I'm compiling, all I do is call these functions,
then print something out to the console):
main.cpp:5: undefined reference to `curl_global_init'
main.cpp:7: undefined reference to `curl_global_cleanup'

If I force Codeblocks to use "libcurl.a" specifically (like what section
5.7 in the faq tells me to do if I'm using MinGW), the error count jumps
from two to 50 with every error pointing specifically to the file
"libcurl.a", these are just some of the new errors:
lib\libcurl.a(easy.o):(.text+0x16): undefined reference to `WSAStartup_at_8'
lib\libcurl.a(easy.o):(.text+0x39): undefined reference to `WSACleanup_at_0'
lib\libcurl.a(select.o):(.text+0x2e): undefined reference to
lib\libcurl.a(select.o):(.text+0x2aa): undefined reference to `select_at_20'
lib\libcurl.a(select.o):(.text+0x2b7): undefined reference to
lib\libcurl.a(select.o):(.text+0x43f): undefined reference to
lib\libcurl.a(select.o):(.text+0x455): more undefined references to
`__WSAFDIsSet_at_8' follow
lib\libcurl.a(select.o):(.text+0x7a9): undefined reference to `select_at_20'
lib\libcurl.a(select.o):(.text+0x7b8): undefined reference to
lib\libcurl.a(select.o):(.text+0x8b8): undefined reference to
lib\libcurl.a(asyn-thread.o):(.text+0x9d): undefined reference to
lib\libcurl.a(url.o):(.text.unlikely+0x8f): undefined reference to
lib\libcurl.a(url.o):(.text.unlikely+0x96): undefined reference to
lib\libcurl.a(url.o):(.text.unlikely+0xfe): undefined reference to
lib\libcurl.a(url.o):(.text.unlikely+0x122): undefined reference to
lib\libcurl.a(url.o):(.text.unlikely+0x1a4): undefined reference to
lib\libcurl.a(sendf.o):(.text+0x147): undefined reference to `recv_at_16'
lib\libcurl.a(sendf.o):(.text+0x161): undefined reference to
lib\libcurl.a(sendf.o):(.text+0x7ae): undefined reference to `recv_at_16'
lib\libcurl.a(sendf.o):(.text+0x7cd): undefined reference to
lib\libcurl.a(sendf.o):(.text+0x852): undefined reference to `send_at_16'
lib\libcurl.a(sendf.o):(.text+0x871): undefined reference to
lib\libcurl.a(connect.o):(.text+0x74): undefined reference to
lib\libcurl.a(connect.o):(.text+0xa9): undefined reference to
lib\libcurl.a(connect.o):(.text+0x10b): undefined reference to `ntohs_at_4'

If I force Codeblocks to use "libcurldll.a" then if finishes compilation
and linking without any errors, but, unsurprisingly, the application
looks for a dll file. This, however, is something that I don't want the
program doing since I plan to copy the final exe into multiple different
directories on my harddrive and I don't want the dll files to be present
in every directory the exe is in, nor do I want to put the dll in my
system32 since that's just a workaround, which I would like to avoid if
possible. This is the code for my test program:
int main()
     CURLcode hand = curl_global_init(CURL_GLOBAL_WIN32);
     std::cout << "Test";
     return 0;
Also, I've made sure that the -DCURL_STATICLIB flag is set when I
compile the program, here's the full command in Codeblocks' Build Log
after I point it specifically to "libcurl.a":
mingw32-g++.exe -Wall -fexceptions -g -DCURL_STATICLIB
-I"C:\Users\G\Desktop\selection\Win32 -
Generic\libcurl\curl-7.32.0-devel-mingw32\include" -c
C:\Users\G\Desktop\project\main.cpp -o obj\Debug\main.o
C:\Users\G\Desktop\project\main.cpp: In function 'int main()':
C:\Users\G\Desktop\project\main.cpp:6:14: warning: unused variable
'hand' [-Wunused-variable]
mingw32-g++.exe -L"C:\Users\G\Desktop\selection\Win32 -
Generic\libcurl\curl-7.32.0-devel-mingw32\lib" -o
bin\Debug\RandomEp.exe obj\Debug\main.o
"C:\Users\G\Desktop\selection\Win32 -
After that line the "undefined reference" errors start popping up

A majority of the pitfalls I've seen on the mail-list relate to building
curl and the curl libraries from the source code, so the answers have
been similar to "go into this directory and run the make file with
arguments x, y, and z" which doesn't apply to my situation since, to my
knowledge, the ./configure, make, make install trio of commands can't be
run in windows' command prompt. Other problems either deal specifically
with Visual Studio, require using the curl-config tool (which I can't
use since I'm neither downloading a binary package nor building from
source), or just reference "5.7 Link errors when building libcurl on
Windows!" in the faq, which has proven unhelpful.

If I had downloaded the package from some blogspot page or any webpage
that wasn't directly related to the curl website, I wouldn't hesitate to
just give up on the package, download the source from git, and compile
it myslef (I may end up doing that in the end since I only need the http
functionality of curl), but since I'm getting the package directly from
the curl download page and the "build.txt" file inside the package
itself tells me that I should be able to link to the libraries both
dynamically and statically, It confuses me why I can't link to any of
the libraries that are provided to the point where I'm more interested
in solving this dilemma than I am in completing my program (half the
reason I made it in the first place was so it could be a learning
experience for me in using Codeblocks and non-standard libraries in C++).
List admin:
Received on 2013-08-22