A lot of undefined reference errors when using wxWidgets(3.0.2) as static build

2.2k views Asked by At

I saw a lot of posts about this but no one helped me... My problem is that I want to use the static build so I can execute the compiled exe of my project without other files...

I compiled wxWidgets with the following commands:

mingw32-make -f makefile.gcc -j4 SHARED=0 MONOLITHIC=1 UNICODE=1 BUILD=release clean
mingw32-make -f makefile.gcc -j4 SHARED=0 MONOLITHIC=1 UNICODE=1 BUILD=release

But when I am using the build in CodeBlocks I get a lot of undefined reference errors

Link with the full list of errors: http://pastebin.com/2Ccs9nDu

In Codeblocks its using the following commands to compile:

mingw32-g++.exe -LD:\wxWidgets-3.0.2\lib\gcc_lib -o bin\Release\Test.exe obj\Release\TestApp.o obj\Release\Test.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 -mwindows

And these are the liked libarys:

        <Add option="-mthreads" />
        <Add library="libkernel32.a" />
        <Add library="libuser32.a" />
        <Add library="libgdi32.a" />
        <Add library="libwinspool.a" />
        <Add library="libcomdlg32.a" />
        <Add library="libadvapi32.a" />
        <Add library="libshell32.a" />
        <Add library="libole32.a" />
        <Add library="liboleaut32.a" />
        <Add library="libuuid.a" />
        <Add library="libcomctl32.a" />
        <Add library="libwsock32.a" />
        <Add library="libodbc32.a" />

Can anybody Help me? I red so much about it but I still dont know how I can fix this problem in Codeblocks. And sorry if I missed some important part.. I sadly dont know a lot about this topic because I just startet to use it.

PS: The non-static build works for me, only the static makes trouble...

PPS: I dont think it was a duplication of the post... I dont get the soloution out of the linked page... Please open this post again..

edit: here are the linker for the wxWidgets libaries:

            <Linker>
                <Add option="-s" />
                <Add library="libwxmsw30u.a" />
                <Add library="libwxpng.a" />
                <Add library="libwxjpeg.a" />
                <Add library="libwxtiff.a" />
                <Add library="libwxzlib.a" />
                <Add directory="D:/Project/wxWidgets-3.0.2/lib/gcc_lib" />
            </Linker>

Edit: This is how Code::Blocks compiles my Project

mingw32-g++.exe -LD:\Project\wxWidgets-3.0.2\lib\gcc_lib -o bin\Release\static_Test.exe  
obj\Release\static_TestApp.o obj\Release\static_TestMain.o obj\Release\resource.res 
-s -mthreads  -lwxmsw30u_core -lwxbase30u -lwxpng -lwxzlib -lkernel32 -luser32 
-lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 
-lwsock32 -lodbc32 -mwindows
2

There are 2 answers

12
ravenspoint On

You need to tell the linker to search for the static library in the folder where it was built - something like ...\wxWidgets-3.0.1\gcc_static_lib.

So change

mingw32-g++.exe -LD:\wxWidgets-3.0.2\wx\lib\gcc_lib

to

mingw32-g++.exe -LD:\wxWidgets-3.0.2\wx\gcc_static_lib

The easiest way to do that is to set a global variable. Do you know how to use this code::blocks feature?

enter image description here

enter image description here

0
Mahdi Khalili On
g++ `wx-config --cxxflags` -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0/ -I/usr/include/wx-3.0 -D_File_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -Wall -g -c mycode.cpp  -o mycode.o `wx-config --libs`

use this console command in linux to compile your code change mycode.cpp to your main file and mycode.o to output file for windows its a little bit different and longer, code::blocks will show you alternative command for windows if you compile sample project in it.