I'm trying to statically link libcurl in codeblocks on Windows.
I compiled libcurl with "mingw32-make mingw32", and have linked the resulting libraries libcurl.a and libcurldll.a. I saw another post on ere that suggested the solution was to add option -lwldap32, but that's made no difference :/
What am I missing?
EDIT: Here's a sample of the first compile command that completed successfully:
mingw32-g++.exe -Wall -pipe -mthreads -std=gnu++14 -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -O2 -DCURL_STATICLIB -IE:\plus\libs\wxWidgets\include -IE:\plus\libs\curl-7.43.0\include -IE:\plus\libs\wxWidgets\lib\gcc_lib\mswu -c E:\plus\projects\hlr\hlrMain.cpp -o obj\Release\hlrMain.o
E:\plus\projects\hlr\hlrMain.cpp:165:1: warning: 'virtual bool wxEvtHandler::TryValidator(wxEvent&)' is deprecated [-Wdeprecated-declarations]
}
^
In file included from E:\plus\libs\wxWidgets\include/wx/menu.h:14:0,
from E:\plus\projects\hlr\hlrMain.h:14,
from E:\plus\projects\hlr\hlrMain.cpp:10:
E:\plus\libs\wxWidgets\include/wx/event.h:3683:22: note: declared here
virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false; )
^
E:\plus\libs\wxWidgets\include/wx/defs.h:615:43: note: in definition of macro 'wxDEPRECATED'
#define wxDEPRECATED(x) wxDEPRECATED_DECL x
^
E:\plus\libs\wxWidgets\include/wx/event.h:3682:5: note: in expansion of macro 'wxDEPRECATED_BUT_USED_INTERNALLY_INLINE'
wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
^
E:\plus\projects\hlr\hlrMain.cpp:165:1: warning: 'virtual bool wxEvtHandler::TryParent(wxEvent&)' is deprecated [-Wdeprecated-declarations]
}
Link to full output with lots of warnings here: http://pastebin.com/a6s0mwQ7
Failed compile:
mingw32-g++.exe -LE:\plus\libs\wxWidgets\lib\gcc_lib -o bin\Release\hlr.exe obj\Release\hlrApp.o obj\Release\hlrMain.o obj\Release\resource.res -s -lwldap32 -mthreads -lwxmsw30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib E:\plus\libs\curl-7.43.0\lib\libcurl.a E:\plus\libs\curl-7.43.0\lib\libcurldll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
E:\plus\libs\curl-7.43.0\lib\libcurl.a(connect.o):(.text+0xbda): undefined reference to `_imp__WSAIoctl#36'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x145): undefined reference to `_imp__ldap_err2string'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x187): undefined reference to `_imp__ldap_msgfree'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x1b4): undefined reference to `_imp__ldap_unbind_s'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x41f): undefined reference to `_imp__ldap_set_option'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x444): undefined reference to `_imp__ldap_init'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x47b): undefined reference to `_imp__ldap_simple_bind_s'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x4f1): undefined reference to `_imp__ldap_err2string'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5a9): undefined reference to `_imp__ldap_search_s'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5c2): undefined reference to `_imp__ldap_err2string'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5f1): undefined reference to `_imp__ldap_first_entry'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x62c): undefined reference to `_imp__ldap_get_dn'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x6cc): undefined reference to `_imp__ldap_memfree'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x6e9): undefined reference to `_imp__ldap_first_attribute'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x71e): undefined reference to `_imp__ldap_get_values_len'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x911): undefined reference to `_imp__ldap_value_free_len'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x91e): undefined reference to `_imp__ldap_memfree'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x93b): undefined reference to `_imp__ber_free'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x983): undefined reference to `_imp__ldap_value_free_len'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x990): undefined reference to `_imp__ldap_memfree'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x9ef): undefined reference to `_imp__ldap_next_attribute'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa14): undefined reference to `_imp__ber_free'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa29): undefined reference to `_imp__ldap_next_entry'
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa69): undefined reference to `_imp__ldap_memfree'
For anyone else having this problem, turned out that I needed to add the ws2_32 lib by adding a linker settings->link library in code::blocks, using the full filename libws2_32.a.
Adding -lws2_32 as suggested elsewhere online wasn't enough for some reason.
Compile command now is:
mingw32-g++.exe -LE:\plus\libs\wxWidgets\lib\gcc_lib -o bin\Release\hlr.exe obj\Release\hlrApp.o obj\Release\hlrMain.o obj\Release\resource.res -s -mthreads -lwxmsw30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 E:\plus\libs\curl-7.43.0\lib\libcurl.a E:\plus\compilers\MinGW\i686-w64-mingw32\lib\libws2_32.a E:\plus\compilers\MinGW\i686-w64-mingw32\lib\libwldap32.a -mwindows
Curl depends on OpenSSL. Make sure you have linked it.
_imp__WSAIoctl is a part of "Ws2.lib"(Ws2_32.lib), header "winsock2.h". Try make sure that this reference is resolved in your project.
Related
I built SDL (2.0.10) using cmake and now I am trying to link it to my application.
For linking I use g++ $(OBJS) -L./Path/To/SDL/LibFolder -lmingw32 -lSDL2main -lSDL2-static -oOut.exe
When I link it dynamically using SDL2, it works without problems. But I would like to link it statically.
I tried including every library that I found in error log (-lkernel32 -ladvapi32 -lgdi32 -limm32 -lmsvcrt -lole32 -loleaut32 -lsetupapi -lshell32 -luser32 -lversion -lwinmm -lmingw32 -lSDL2main -lSDL2-static), but it did nothing. I guess I don't understand how this linking stuff works.
It outputs this: (There is more, but I want to keep it simple. There are more undefined references to libraries that I listed above.)
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windows.c.obj): In function `WIN_CoInitialize':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/core/windows/SDL_windows.c:76: undefined reference to `__imp_CoInitializeEx'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windows.c.obj): In function `WIN_CoUninitialize':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/core/windows/SDL_windows.c:95: undefined reference to `__imp_CoUninitialize'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_SetupAPI':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:650: undefined reference to `ImmGetIMEFileNameA'
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:732: undefined reference to `ImmGetCompositionStringW'
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:737: undefined reference to `ImmGetCompositionStringW'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_HandleMessage':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:901: undefined reference to `ImmReleaseContext'
./deps/windows/sdl/lib/libSDL2-static.a(SDL_windowskeyboard.c.obj): In function `IME_ClearComposition':
D:/Users/alesg/Desktop/comp/SDL-mirror/src/video/windows/SDL_windowskeyboard.c:716: undefined reference to `ImmGetContext'
Compiling code that uses GLFW in MinGW-w64, everything goes fine until the linking phase. At this point, ld starts to complain about undefined references to GLFW functions, even though I specified the additional library directories and used libraries. Here's my g++ invocation (I, of course, use a lot of enviroment variables in my batch file to shorten the command, here it is unwrapped):
x86_64-w64-mingw32-g++.exe -I./deps/glfw-3.2.1/include -I./deps/gl3w/include -I./include -L./deps/glfw-3.2.1/lib-mingw-w64/x86_64 -lglfw3 -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32 -std=c++14 -fpermissive -mwindows -o build\out\windows\Release\x86_64\GemVerse.exe ./deps/gl3w/src/gl3w.c ./src/main.cpp
Here is the same command, broken down:
x86_64-w64-mingw32-g++.exe %INCLUDEDIRS% %LIBDIRS64% %CFLAGS% %LIBS% -o build\out\windows\Release\x86_64\GemVerse.exe %SOURCES%
Where %INCLUDEDIRS%=-I./deps/glfw-3.2.1/include -I./deps/gl3w/include -I./deps/glm-0.9.9.3/include -I./include, %LIBDIRS64%=-L./deps/glfw-3.2.1/lib-mingw-w64/x86_64, %LIBS%=-lglfw3 -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32, %CFLAGS%=-std=c++14 -fpermissive -mwindows and %SOURCES%=./deps/gl3w/src/gl3w.c ./src/main.cpp
As you can see, the library gets found and linked, but the symbols are still unresolved. How is this possible and how to link GLFW properly?
EDIT 1:I've changed the library order, now it's -lopengl32 -lgdi32 -lkernel32 -luser32 -lcomdlg32 -glfw3, so that GLFW is at the end. That didn't fix the problem, ld still doesn't find the definitions. Here is the g++ log, since I don't seem to have attached one, my fault:
./deps/gl3w/src/gl3w.c: In function 'int open_libgl()':
./deps/gl3w/src/gl3w.c:47:52: warning: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
*(void **)(&wgl_get_proc_address) = GetProcAddress(libgl, "wglGetProcAddress");
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x65): undefined reference to `glfwInit'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x74): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x83): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x92): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0x9e): undefined reference to `glfwWindowHint'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0xc0): undefined reference to `glfwCreateWindow'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text$_ZN8gemverse6GVGame4initEv[_ZN8gemverse6GVGame4initEv]+0xd4): undefined reference to `glfwMakeContextCurrent'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x1b): undefined reference to `glfwTerminate'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x3b): undefined reference to `glfwGetKey'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x5c): undefined reference to `glfwSwapBuffers'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x61): undefined reference to `glfwPollEvents'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x66): undefined reference to `glfwTerminate'
C:\Users\vtonc\AppData\Local\Temp\cc6GSYa1.o:main.cpp:(.text.startup+0x7d): undefined reference to `glfwSetWindowShouldClose'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
Some names are mangled, since the initialization code in my project is incapsulated into a class.
I fixed the problem by putting %SOURCES% before %LIBS% in the g++ invocation, thanks to this answer. That seems to make difference as well: not only the library order is important, but the order of inputs (sources before libraries) too.
When attempting to build the wxWidgets 3.1.0 library with the following command line:
mingw32-make -f makefile.gcc BUILD=release SHARED=1 CFLAGS="-O2 -flto"
CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto"
I'm getting this warning (31 occurrences)
lto1.exe: warning: -fPIC ignored for target (all code is position independent)
Followed by:
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x13c4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x1418): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3792): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x37c1): undefined reference to `wx_regerror'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x3a7d): undefined reference to `wx_re_exec'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x47de): undefined reference to `wx_re_comp'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4cf4): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans6.ltrans.o:<artificial>:(.text+0x4f94): undefined reference to `wx_regfree'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x57c): undefined reference to `deflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x88d): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x8ba): undefined reference to `deflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x947): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x4830): undefined reference to `deflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans12.ltrans.o:<artificial>:(.text+0x59f4): undefined reference to `deflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x3354): undefined reference to `deflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans14.ltrans.o:<artificial>:(.text+0x38db): undefined reference to `inflateReset'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x21d): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x24a): undefined reference to `inflateSetDictionary'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x266): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x27d): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x2d0): undefined reference to `zlibVersion'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x121c): undefined reference to `inflate'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x1924): undefined reference to `inflateEnd'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x20b7): undefined reference to `inflateInit2_'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x3694): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5534): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x5813): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x773e): undefined reference to `crc32'
C:\Users\Marc\AppData\Local\Temp\ccEDEhIg.ltrans16.ltrans.o:<artificial>:(.text+0x7c5b): undefined reference to `crc32'
collect2.exe: error: ld returned 1 exit status
makefile.gcc:5299: recipe for target '..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll' failed
mingw32-make: *** [..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll] Error 1
Last lines emmited by the compiler and linker, which results in all these errors, are as follows:
g++ -c -o gcc_mswudll\basedll_main.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_main.o -MFgcc_mswudll\basedll_main.o.d -MD -MP ../../src/msw/main.cpp
g++ -c -o gcc_mswudll\basedll_volume.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I..\..\lib\gcc_dll\mswu -I..\..\include -W -Wall -DWXBUILDING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib -I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswudll\basedll_volume.o -MFgcc_mswudll\basedll_volume.o.d -MD -MP ../../src/msw/volume.cpp
g++ -shared -fPIC -o ..\..\lib\gcc_dll\wxbase310u_gcc_custom.dll gcc_mswudll\basedll_dummy.o gcc_mswudll\basedll_version_rc.o gcc_mswudll\basedll_any.o gcc_mswudll\basedll_appbase.o gcc_mswudll\basedll_arcall.o gcc_mswudll\basedll_arcfind.o gcc_mswudll\basedll_archive.o gcc_mswudll\basedll_arrstr.o gcc_mswudll\basedll_base64.o gcc_mswudll\basedll_clntdata.o gcc_mswudll\basedll_cmdline.o gcc_mswudll\basedll_config.o gcc_mswudll\basedll_convauto.o gcc_mswudll\basedll_datetime.o gcc_mswudll\basedll_datetimefmt.o gcc_mswudll\basedll_datstrm.o gcc_mswudll\basedll_dircmn.o gcc_mswudll\basedll_dynarray.o gcc_mswudll\basedll_dynlib.o gcc_mswudll\basedll_dynload.o gcc_mswudll\basedll_encconv.o gcc_mswudll\basedll_evtloopcmn.o gcc_mswudll\basedll_extended.o gcc_mswudll\basedll_ffile.o gcc_mswudll\basedll_file.o gcc_mswudll\basedll_fileback.o gcc_mswudll\basedll_fileconf.o gcc_mswudll\basedll_filefn.o gcc_mswudll\basedll_filename.o gcc_mswudll\basedll_filesys.o gcc_mswudll\basedll_filtall.o gcc_mswudll\basedll_filtfind.o gcc_mswudll\basedll_fmapbase.o gcc_mswudll\basedll_fs_arc.o gcc_mswudll\basedll_fs_filter.o gcc_mswudll\basedll_hash.o gcc_mswudll\basedll_hashmap.o gcc_mswudll\basedll_init.o gcc_mswudll\basedll_intl.o gcc_mswudll\basedll_ipcbase.o gcc_mswudll\basedll_languageinfo.o gcc_mswudll\basedll_list.o gcc_mswudll\basedll_log.o gcc_mswudll\basedll_longlong.o gcc_mswudll\basedll_memory.o gcc_mswudll\basedll_mimecmn.o gcc_mswudll\basedll_module.o gcc_mswudll\basedll_mstream.o gcc_mswudll\basedll_numformatter.o gcc_mswudll\basedll_object.o gcc_mswudll\basedll_platinfo.o gcc_mswudll\basedll_powercmn.o gcc_mswudll\basedll_process.o gcc_mswudll\basedll_regex.o gcc_mswudll\basedll_stdpbase.o gcc_mswudll\basedll_sstream.o gcc_mswudll\basedll_stdstream.o gcc_mswudll\basedll_stopwatch.o gcc_mswudll\basedll_strconv.o gcc_mswudll\basedll_stream.o gcc_mswudll\basedll_string.o gcc_mswudll\basedll_stringimpl.o gcc_mswudll\basedll_stringops.o gcc_mswudll\basedll_strvararg.o gcc_mswudll\basedll_sysopt.o gcc_mswudll\basedll_tarstrm.o gcc_mswudll\basedll_textbuf.o gcc_mswudll\basedll_textfile.o gcc_mswudll\basedll_threadinfo.o gcc_mswudll\basedll_time.o gcc_mswudll\basedll_timercmn.o gcc_mswudll\basedll_timerimpl.o gcc_mswudll\basedll_tokenzr.o gcc_mswudll\basedll_translation.o gcc_mswudll\basedll_txtstrm.o gcc_mswudll\basedll_unichar.o gcc_mswudll\basedll_uri.o gcc_mswudll\basedll_ustring.o gcc_mswudll\basedll_variant.o gcc_mswudll\basedll_wfstream.o gcc_mswudll\basedll_wxcrt.o gcc_mswudll\basedll_wxprintf.o gcc_mswudll\basedll_xlocale.o gcc_mswudll\basedll_xti.o gcc_mswudll\basedll_xtistrm.o gcc_mswudll\basedll_zipstrm.o gcc_mswudll\basedll_zstream.o gcc_mswudll\basedll_fswatchercmn.o gcc_mswudll\basedll_fswatcherg.o gcc_mswudll\basedll_basemsw.o gcc_mswudll\basedll_crashrpt.o gcc_mswudll\basedll_debughlp.o gcc_mswudll\basedll_dde.o gcc_mswudll\basedll_dir.o gcc_mswudll\basedll_dlmsw.o gcc_mswudll\basedll_evtloopconsole.o gcc_mswudll\basedll_mimetype.o gcc_mswudll\basedll_power.o gcc_mswudll\basedll_regconf.o gcc_mswudll\basedll_registry.o gcc_mswudll\basedll_snglinst.o gcc_mswudll\basedll_stackwalk.o gcc_mswudll\basedll_stdpaths.o gcc_mswudll\basedll_thread.o gcc_mswudll\basedll_timer.o gcc_mswudll\basedll_utils.o gcc_mswudll\basedll_utilsexc.o gcc_mswudll\basedll_fswatcher.o gcc_mswudll\basedll_event.o gcc_mswudll\basedll_fs_mem.o gcc_mswudll\basedll_msgout.o gcc_mswudll\basedll_utilscmn.o gcc_mswudll\basedll_main.o gcc_mswudll\basedll_volume.o -mthreads -L..\..\lib\gcc_dll -Wl,--out-implib=..\..\lib\gcc_dll\libwxbase31u.a -O2 -flto -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
What I've tried so far:
Added -fPIC to CFLAGS and CXXFLAGS, to no avail.
Use -fwhopr instead of -flto, as suggested by the MinGW-w64 Wiki but it's not recognized by either gcc.exe and g++.exe. After reading this article: Linktime optimization in GCC, part 1 - brief history, I'm assuming the -fwhopr option doesn't exist anymore and is now the default mode for the -flto switch.
Build the static configuration (SHARED=0). It builds successfully, but is unusable. See Reference #1.
Omit -flto from LDFLAGS - i.e. use -flto in CFLAGS and CXXFLAGS only. Also no avail.
How to get past these errors, and build wxWidgets with GCC's Link Time Optimization?
I'm building with MinGW-w64; threading model Win32; exception handling DWARF; GCC version 5.3.0.
Reference #1: Result from the "Minimal Sample" build command line
H:\temp\wxwidgets-3.1.0\samples\minimal>mingw32-make -f makefile.gcc BUILD=release SHARED=0 CFLAGS="-O2 -flto" CXXFLAGS="-O2 -flto" LDFLAGS="-O2 -flto"
windres --use-temp-file -i../../samples/sample.rc -ogcc_mswu\minimal_sample_rc.o --define __WXMSW__ --define NDEBUG --define _UNICODE --include-dir .\..\..\lib\gcc_lib\mswu --include-dir ./../../include --include-dir . --include-dir ./../../samples --define NOPCH
g++ -c -o gcc_mswu\minimal_minimal.o -O2 -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -I.\..\..\lib\gcc_lib\mswu -I.\..\..\include -W -Wall -I. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -O2 -flto -MTgcc_mswu\minimal_minimal.o -MFgcc_mswu\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswu\minimal.exe gcc_mswu\minimal_sample_rc.o gcc_mswu\minimal_minimal.o -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows -O2 -flto -lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x191): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x197): undefined reference to `wxDefaultPosition'
C:\Users\Marc\AppData\Local\Temp\ccY1ZbWs.ltrans0.ltrans.o:<artificial>:(.text+0x1a8): undefined reference to `wxDefaultSize'
(Many, many other "undefined reference" errors - probably one for every function the code ever depends on) and then...
collect2.exe: error: ld returned 1 exit status
makefile.gcc:221: recipe for target 'gcc_mswu\minimal.exe' failed
mingw32-make: *** [gcc_mswu\minimal.exe] Error 1
I've never tried using LTO with DLLs before, but there are apparently bugs with doing it, see e.g. this one. Not sure if using the workaround proposed there can help in your case.
What I think should definitely work would be compiling your application sources and wxWidgets together at once, this would be similar to building a static library but shouldn't optimize away things unused in the library -- but used in the application code.
Finally, I'm really not sure if you're going to achieve much with LTO in wxWidgets case. There is not that much "slow" code to optimize in the library...
I am trying to use cUrl in my app but i am getting several errors. I already tried to find a solution on g or here, but nothing helped.
I build and link cUrl as static, have libcurl.a set up in linker, have proper includes but it still doesn't work.
I tried adding -lcurl into build settings but seems like it doesn't know that flag.
I am using cUrl 7.46.0 build with --disable--static and --without--ssl
and Code::Blocks ide & mingw compiler // c++ ofc
Here are those errors:
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_cleanup'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_init'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_setopt'
obj\Release\src\HTTPDownloadRequest.o:HTTPDownloadRequest.cpp| undefined reference to `_imp__curl_easy_perform'
Compilation command:
mingw32-g++.exe -LC:\WXWID\lib\gcc_lib -o bin\Release\app.exe obj\Release\app.o obj\Release\appMain.o obj\Release\appHistory.o obj\Release\src\HTTPDownloadRequest.o obj\Release\resource.res -s -static-libgcc -static-libstdc++ -static -mthreads -lwxmsw30u_core -lwxbase30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib C:\WXWID\lib\gcc_lib\libwxmsw30u_adv.a "C:\curl\lib\libcurl.a" -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
Errors when used define CURL_STATICLIB
C:\curl\lib\libcurl.a(libcurl_la-connect.o)| undefined reference to `WSAIoctl#36'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_err2stringA'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)| undefined reference to `_imp__ldap_msgfree'
C:\curl\lib\libcurl.a(libcurl_la-ldap.o)|| undefined reference to `_imp__ldap_unbind_s'
...
If you try to link with static libcurl add -DCURL_STATICLIB to gcc arguments or define CURL_STATICLIB macro before including its headers to use correct mangling.
I would do
mingw32-g++.exe -LC:\curl\lib -lcurl ................
I'm trying to cross-compile cachecoin binaries on a linux host using gitian and i686-w64-mingw for a windows target.
The compilation works fine until the final step of static linking of the dependencies. This is what I get:
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x1ff): undefined reference to `__imp__CertFreeCertificateContext#4'
Google suggests it's a missing -lcrypto link or even -lcrypt32. But in the last line before it fails you can see it's linking both. What's the issue here?
My gitian descriptor is available here. And this is the qmake project file. Full tail of the build log:
[...]
i686-w64-mingw32-g++ -c -frandom-seed=cachecoin -D_FORTIFY_SOURCE=2 -msse2 -O2 -frtti -fexceptions -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector -DBOOST_THREAD_USE_LIB -DQT_GUI -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN -D__NO_SYSTEM_INCLUDES -DSCRYPT_CHACHA -DSCRYPT_KECCAK512 -DUSE_QRCODE -DUSE_UPNP=1 -DSTATICLIB -DUSE_IPV6=1 -DCACHECOIN_NEED_QT_PLUGINS -DHAVE_BUILD_INFO -DWIN32 -D_MT -DQT_THREAD_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I'../../staging32/include/QtCore' -I'../../staging32/include/QtNetwork' -I'../../staging32/include/QtGui' -I'../../staging32/include' -I'../../staging32' -I'src' -I'src/json' -I'src/qt' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32/include/ActiveQt' -I'build' -I'build' -I'../../staging32/mkspecs/unsupported/win32-g++-cross' -o build/moc_qrcodedialog.o build/moc_qrcodedialog.cpp
i686-w64-mingw32-g++ -c -frandom-seed=cachecoin -D_FORTIFY_SOURCE=2 -msse2 -O2 -frtti -fexceptions -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector -DBOOST_THREAD_USE_LIB -DQT_GUI -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN -D__NO_SYSTEM_INCLUDES -DSCRYPT_CHACHA -DSCRYPT_KECCAK512 -DUSE_QRCODE -DUSE_UPNP=1 -DSTATICLIB -DUSE_IPV6=1 -DCACHECOIN_NEED_QT_PLUGINS -DHAVE_BUILD_INFO -DWIN32 -D_MT -DQT_THREAD_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I'../../staging32/include/QtCore' -I'../../staging32/include/QtNetwork' -I'../../staging32/include/QtGui' -I'../../staging32/include' -I'../../staging32' -I'src' -I'src/json' -I'src/qt' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32' -I'../../staging32/include/ActiveQt' -I'build' -I'build' -I'../../staging32/mkspecs/unsupported/win32-g++-cross' -o build/qrc_cachecoin.o release/qrc_cachecoin.cpp
i686-w64-mingw32-g++ -Wl,--dynamicbase -Wl,--nxcompat -Wl,--large-address-aware -static-libgcc -static-libstdc++ -Wl,-s -lmingwthrd -Wl,-subsystem,windows -o release/cachecoin-qt.exe object_script.cachecoin-qt.Release -L'/home/ubuntu/staging32/lib' -lmingwthrd -lmingw32 -lqtmain build/cachecoin-qt_res.o -lqrencode -L/home/ubuntu/staging32 -lminiupnpc -liphlpapi -L/home/ubuntu/staging32 -L/home/ubuntu/staging32 -L/home/ubuntu/staging32 -L/home/ubuntu/staging32 -ldb_cxx -lshlwapi -lmswsock -lcrypt32 -lboost_system-mt-s -lboost_filesystem-mt-s -lboost_program_options-mt-s -lboost_thread_win32-mt-s -lboost_chrono-mt-s -L/home/ubuntu/staging32/plugins/codecs -lqcncodecs -lqjpcodecs -lqtwcodecs -lqkrcodecs -L/home/ubuntu/staging32/plugins/accessible -lqtaccessiblewidgets -lQtGui -lQtNetwork -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -L/home/ubuntu/deps32/lib -lssl -lcrypto -lgdi32 -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x1ff): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x27f): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0xbf8): undefined reference to `__imp__CertGetCertificateContextProperty#16'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x20f6): undefined reference to `__imp__CertOpenStore#20'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x212d): undefined reference to `__imp__CertEnumCertificatesInStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2208): undefined reference to `__imp__CertDuplicateCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2291): undefined reference to `__imp__CertCloseStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x23c6): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2648): undefined reference to `__imp__CertGetCertificateContextProperty#16'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x27cc): undefined reference to `__imp__CertGetCertificateContextProperty#16'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2bc9): undefined reference to `__imp__CertOpenStore#20'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2ce2): undefined reference to `__imp__CertOpenStore#20'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2d4d): undefined reference to `__imp__CertFindCertificateInStore#24'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2d7d): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2d94): undefined reference to `__imp__CertCloseStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2db3): undefined reference to `__imp__CertEnumCertificatesInStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x2e25): undefined reference to `__imp__CertEnumCertificatesInStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3777): undefined reference to `__imp__CertOpenStore#20'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x37a8): undefined reference to `__imp__CertCloseStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3829): undefined reference to `__imp__CertEnumCertificatesInStore#8'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x388d): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x38c9): undefined reference to `__imp__CertFindCertificateInStore#24'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x39ef): undefined reference to `__imp__CertFreeCertificateContext#4'
/home/ubuntu/staging32/lib/libcrypto.a(e_capi.o):e_capi.c:(.text+0x3a9b): undefined reference to `__imp__CertFreeCertificateContext#4'
collect2: ld returned 1 exit status
make[1]: *** [release/cachecoin-qt.exe] Error 1
make[1]: Leaving directory `/home/ubuntu/build32/distsrc'
make: *** [release] Error 2
Any ideas?
(I'd rather post ask in the comments first, but I don't have enough reputation yet.)
Judging purely from your post (I haven't tried compiling the program myself), it could be one of these three issues:
wrong order of libraries in the command line (try appending one more -lcrypt32 to it)
the import libraries provided by your mingw-w64 packages are incomplete (you can use nm libcrypt32.a | grep ' T ' to check)
the functions are imported incorrectly (dllimport vs. dllexport vs. undecorated, calling conventions, ...)
After examining the error log once more, I'm inclined to believe it's the first option, as libcrypto seems to be importing functions from libcrypt32, but -lcrypto is almost at the end of the command line and it's not followed by any -lcrypt32.