C++ – Link issue with wxWidget samples on Ubuntu 12.04 (amd64).

Link issue with wxWidget samples on Ubuntu 12.04 (amd64)…. here is a solution to the problem.

Link issue with wxWidget samples on Ubuntu 12.04 (amd64).

I’m > the wxWidget sample application () There was a problem with the link stored in main.cpp. I tried compiling and linking it using:

g++ `wx-config --cxxflags --libs` main.cpp 

The output I get is as follows:

/tmp/ccFHWUaX.o: In function `wxCreateApp()':
main.cpp:(.text+0x31): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)'
/tmp/ccFHWUaX.o: In function `main':
main.cpp:(.text+0x91): undefined reference to `wxEntry(int&, char**)'
/tmp/ccFHWUaX.o: In function `MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&)':
main.cpp:(.text+0x1d2): undefined reference to `wxFrameNameStr'
main.cpp:(.text+0x267): undefined reference to `wxEmptyString'
main.cpp:(.text+0x2ea): undefined reference to `wxEmptyString'
main.cpp:(.text+0x366): undefined reference to `wxMenuBar::wxMenuBar()'
main.cpp:(.text+0x3d1): undefined reference to `wxFrameBase::SetMenuBar(wxMenuBar*)'
main.cpp:(.text+0x3da): undefined reference to `wxStatusLineNameStr'
main.cpp:(.text+0x407): undefined reference to `wxFrame::CreateStatusBar(int, long, int, wxString const&)'
main.cpp:(.text+0x44f): undefined reference to `wxFrameBase::SetStatusText(wxString const&, int)'
main.cpp:(.text+0x533): undefined reference to `wxFrame::~wxFrame()'
(and many lines more...)

WxWidgets-2.8 is installed using the ubuntu repository, whose libraries are located at /usr/lib/x86_64-linux-gnu. I also tried building the specified library path:

-L/usr/lib/x86_64-linux-gnu/

However, this does not change the output. I blamed multi-architecture for my problem, but really just because I didn’t know how it worked.

Can anyone tell me how to build the example correctly?

Thank you.
Michael

When using static linking, libraries must always use the symbols in them after the target file, otherwise they will simply be ignored by the linker because they don’t need to see them at first glance when connecting. So < a href="https://stackoverflow.com/users/1865077/us2012" rel="noreferrer noopener nofollow">us2012 is correct, you need to put the wx-config part after the source file.

You can also use a shared wxWidgets library so that the order doesn’t matter. But it’s still a good practice to use the correct order, and this works for both static and shared libraries anyway.

Related Problems and Solutions