wxWidgets linker errors.

I am currently starting to get into wxWidgets programming. I successfully build wxWidgets, and creating a new wxWidgets project in Code::Blocks works (builds and executes) just fine.

I tried to write an own wxWidgets application from an empty project myself though, and somehow I always fail to build it. My program itself is just some basic hello world program (+ a windows resource file that basically just includes the wxWidgets one),and since the error occurs on the linking stage I think it's pointless to post the source here: I get those errors:

obj\Debug\main.o||In function `wxStringBase':|
C:\Programmieren\wxWidgets-2.8.12\include\wx\string.h|368|undefined reference to `wxStringBase::InitWith(char const*, unsigned int, unsigned int)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV5MyApp[vtable for MyApp]+0x44)||undefined reference to `wxApp::Initialize(int&, char**)'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===|


Info:
wxWidgets version 2.8.12
Compiler: MinGW 4.2.3
IDE: Code::Blocks (02 April 2011 Nightly Build)
Link libraries:
libwxmsw28u.a
Linker options:
-Wl,--enable-auto-import
Search Directories:
Compiler:
$(#wx.include)
$(#wx.lib)\gcc_dll\mswu
Linker:
$(#wx.lib)\gcc_dll
Resource Compiler:
$(#wx.include)
$(#wx.lib)\gcc_dll
$(#wx.lib)\gcc_dll\mswu

I have already compared my settings to the default ones the wxWidgets wizard creates, and haven't found any significant differences.
*bumped*
Sorry, but this really bugs me.
The first question is: Did you make sure that you've listed all needed libs in your environment?

The next thing is this: #include <wx/msw/winundef.h>
I have to include that every once in a while due to windows macros
Well, I define the following macros
1
2
3
4
__GNUWIN32__
__WXMSW__
WXUSINGDLL
wxUSE_UNICODE


Did you make sure that you've listed all needed libs in your environment?

Frankly, I have no idea. As I said, I am new to wxWidgets - though I would have thought that libwxmsw28u.a (I think the MSVC equivalent would be wxmsw28u.lib) is enough. As I said, I looked into the build options of a template wxWidgets project which actually does get compiled and linked just fine (which is also the reason why I am fairly certain that my wxWidgets build is fine).

And again: This is just a basic wxWidgets hello_world program - I really don't do anything else than creating a new frame with the caption "Hello World" and a small menu bar, I don't use any headers other than #include <wx/wx.h> ...

EDIT: Forget it. I have absolutely no idea what I am doing differently, but for some reason it seems to work now.
EDIT2: Now it doesn't work again. Removed the macros and it didn't work anymore, inserted the macros again and it doesn't work. Huh, I have no idea what's going on.
EDIT3: Apparently, it actually has something to do with winundef.h, so thanks for that. But I still have troubles figuring out how exactly it works, cause if I compile it once with winundef.h and then again without it still works... I am a bit confused (epic understatement).
Last edited on
Enable full command-line logging in Code::Blocks and see the output, then do the same.
I already had this on.
The documantation says that the libraries can be build in two ways: monolithic and multilib http://docs.wxwidgets.org/stable/wx_librarieslist.html#librarieslist
the latter is default. Looks like that's your problem?
I did built in monolithic though. And as I said above, the error is fixed when I include winundef.h and define the macros I stated earlier. It's probably just some very weird and very random windows related error.

(Now that I think about it, I think it was stated somewhere that while wx/wx.h usually includes wx/app.h, it doesn't always do so - that might have been the problem here).
If I recall correctly the including of "winundef.h" is needed if you have included <windows.h> or one or two other windows headers.

Tim S.
I think you forgot to link with libwxbase28u.a and libwxmsw28u_core.a. Also you said that you link with libwxmsw28u.a but there is no such library in my system.

Try the simple application here. Just copy and paste for testing.
http://www.zetcode.com/tutorials/wxwidgetstutorial/firstprograms/


It compiles with no problems with my system. Here's the html log from code::blocks.

mingw32-g++.exe -Wall -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -O2 -ID:\dev\lib\wxMSW-2.8.11\include -ID:\dev\lib\wxMSW-2.8.11\lib\gcc_dll\mswu -c "C:\Documents and Settings\Hernandez\Desktop\wx2\simple.cpp" -o obj\Release\simple.o
mingw32-g++.exe -Wall -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -O2 -ID:\dev\lib\wxMSW-2.8.11\include -ID:\dev\lib\wxMSW-2.8.11\lib\gcc_dll\mswu -c "C:\Documents and Settings\Hernandez\Desktop\wx2\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -LD:\dev\lib\wxMSW-2.8.11\lib\gcc_dll -o bin\Release\wx2.exe obj\Release\simple.o obj\Release\main.o -s -lwxbase28u -lwxmsw28u_core


Also note that there is no spaces in your resource compiler directory. Hope that helps.

Good luck!!

[edit]
Fix my sentence.

[edit]
Here's my build, hoping it would help.
mingw32-make -f makefile.gcc BUILD=release SHARED=1 UNICODE=1 USE_OPENGL=1
Last edited on
I already said, I have a monolithic build, so I only need libwxmsw28u.a - I don't even have the two libs you posted. And I already said that it is not related to the libraries I am linking, but to the macros I am defining. I also asked in the wxWidgets forum and in short, it appears to be a Unicode problem combined with that for some reason, my wx/wx.h apparently doesn't include wx/app.h as it should.
I build the same source code from zetcode with monolithic build and works fine for me. What errors are you getting now? Did you have luck on the other forum?

[edit]
Oops!! You're using 2.8.12, mine is 2.8.11. I didn't know a new stable build is release. I'll check that out tomorrow, better sleep for now.

Again good luck!! ^^
Last edited on
Well, as I already said, I got it working with including wx/app.h +
1
2
3
4
#define __GNUWIN32__
#define wxUSING_UNICODE
#define wxUSINGDLL
#define __WXMSW__ 

-- I should probably mark this as solved to avoid further confusion, the only reason I didn't do so yet was cause I was actually hoping someone here would know where this is documented so I can avoid similar errors in the future. Well, whatever.
Last edited on
From docs/tech/tn0019.txt here's the note; if "winundef.h" fixed the problem.

1
2
3
In no event should the Windows headers such as <windows.h> or <commctrl.h> be
included directly. So instead of #include <...> use "wx/msw/wrapwin.h" or
"wx/msw/wrapcctl.h".


Tim S.
Topic archived. No new replies allowed.