6

I installed wxWidgets-2.8.10 following instructions from this page: http://wiki.wxwidgets.org/Compiling_and_getting_started

Libraries directory:

alex@alex-linux:/usr/local/lib$ ls | grep wx
libwx_base-2.8.a
libwx_base_net-2.8.a
libwx_base_xml-2.8.a
libwx_gtk2_adv-2.8.a
libwx_gtk2_aui-2.8.a
libwx_gtk2_core-2.8.a
libwx_gtk2_html-2.8.a
libwx_gtk2_qa-2.8.a
libwx_gtk2_richtext-2.8.a
libwx_gtk2_xrc-2.8.a
libwxtiff-2.8.a
wx

Then I created file widgetTest.cpp and filled it with this code: http://www.wxwidgets.org/docs/tutorials/hworld.txt

Trying to build it, I have a lot of linker errors:

alex@alex-linux:~$ cd /home/alex/Tmp
alex@alex-linux:~/Tmp$ g++ `wx-config --cppflags` `wx-config --libs` widgetTest.cpp
/tmp/ccnPCAw5.o: In function `wxCreateApp()':
widgetTest.cpp:(.text+0x2d): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)'
/tmp/ccnPCAw5.o: In function `main':
...
widgetTest.cpp:(.text._ZN20wxThreadHelperThreadD0Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined reference to `wxThread::~wxThread()'
collect2: ld returned 1 exit status

Additional information:

alex@alex-linux:~$ wx-config --cppflags
-I/usr/local/lib/wx/include/gtk2-ansi-release-static-2.8 -I/usr/local/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__
alex@alex-linux:~$ wx-config --libs
-L/usr/local/lib -pthread   /usr/local/lib/libwx_gtk2_richtext-2.8.a /usr/local/lib/libwx_gtk2_aui-2.8.a /usr/local/lib/libwx_gtk2_xrc-2.8.a /usr/local/lib/libwx_gtk2_qa-2.8.a /usr/local/lib/libwx_gtk2_html-2.8.a /usr/local/lib/libwx_gtk2_adv-2.8.a /usr/local/lib/libwx_gtk2_core-2.8.a /usr/local/lib/libwx_base_xml-2.8.a /usr/local/lib/libwx_base_net-2.8.a /usr/local/lib/libwx_base-2.8.a -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lgio-2.0 -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lXinerama -lSM -lpng -ljpeg -lexpat -lwxtiff-2.8 -lz -ldl -lm 
alex@alex-linux:~$ 

What is wrong?

Alex F
  • 42,307
  • 41
  • 144
  • 212
  • 1
    g++ `wx-config --cppflags` widgetTest.cpp `wx-config --libs` It worked! How can I apply this solution to my working environment - Eclipse CDT. I add `wx-config --cppflags` to GCC compiler settings, and `wx-config --libs` to the linker settings, and get linker errors. – Alex F Mar 03 '10 at 19:07

1 Answers1

10

Does this help?

g++ `wx-config --cppflags` widgetTest.cpp `wx-config --libs`

Sometimes putting the libraries after the sources is required.

Eric Seppanen
  • 5,923
  • 30
  • 24
  • Yes, it is required whenever you use static linking (as the OP does). And being a direct consequence of the search algorithm used by the traditional Unix linkers it's not specific to neither wxWidgets nor Linux. – VZ. Mar 03 '10 at 19:02
  • Moving the libraries to the end helped, command line build succeeded, thank you! Now I return to my working environment: Eclipse CDT. How to reproduce this solution here? In the Compiler settings, I have Other flags: `wx-config --cppflags`, in the Linker settings, I have Other flags `wx-config --libs`. Build results linker errors. – Alex F Mar 03 '10 at 19:18
  • 1
    For reference: In Eclipse CDT the problem is solved by changing linkercommand line pattern: FLAGS is moved to the end. – Alex F Mar 04 '10 at 07:00