Building a project on ubuntu - will not link - undefined reference Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

Here we go again. *sigh*

I have downloaded wxWidgets 3.1, compiled wxWidgets 3.1 using the following configure ../configure --enable webview --enable unicode and am trying to compile my project using codeblocks. I have placed the proper wxconfig calls in the right places but I continue to get the following link errors.

Code: Select all

||=== Build: Release in AutoHarp (compiler: GNU GCC Compiler) ===|
Release/AutoHARP/src/AboutDlg.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AboutDlg.o||In function `wxEventFunctorMethod<wxEventTypeTag<wxWebViewEvent>, wxEvtHandler, wxEvent, wxEvtHandler>::operator()(wxEvtHandler*, wxEvent&)':|
/usr/include/wx-3.0/wx/event.h|399|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AboutDlg.o||In function `wxEventTableEntryBase::wxEventTableEntryBase(int, int, wxEventFunctor*, wxObject*)':|
/usr/include/wx-3.0/wx/event.h|3156|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AboutDlg.o:(.rodata._ZTV20wxMDIParentFrameBase[_ZTV20wxMDIParentFrameBase]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AboutDlg.o:(.rodata._ZTV20wxMDIParentFrameBase[_ZTV20wxMDIParentFrameBase]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AboutDlg.o:(.rodata._ZTV8AboutDlg[_ZTV8AboutDlg]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AboutDlg.o:(.rodata._ZTV8AboutDlg[_ZTV8AboutDlg]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AboutDlg.o:(.rodata._ZTV8AboutDlg[_ZTV8AboutDlg]+0x460)||undefined reference to `wxTopLevelWindowGTK::OnInternalIdle()'|
Release/AutoHARP/src/AddItemDlg.o||In function `wxArrayString::Item(unsigned long)':|
/usr/include/wx-3.0/wx/arrstr.h|177|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddItemDlg.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddItemDlg.o||In function `wxEventFunctorMethod<wxEventTypeTag<wxCommandEvent>, wxEvtHandler, wxEvent, wxEvtHandler>::operator()(wxEvtHandler*, wxEvent&)':|
/usr/include/wx-3.0/wx/event.h|399|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddItemDlg.o:/usr/include/wx-3.0/wx/event.h|399|more undefined references to `wxTrap()' follow|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV19wxNavigationEnabledI8wxWindowE[_ZTV19wxNavigationEnabledI8wxWindowE]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV19wxNavigationEnabledI8wxWindowE[_ZTV19wxNavigationEnabledI8wxWindowE]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV19wxNavigationEnabledI14wxListCtrlBaseE[_ZTV19wxNavigationEnabledI14wxListCtrlBaseE]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV19wxNavigationEnabledI14wxListCtrlBaseE[_ZTV19wxNavigationEnabledI14wxListCtrlBaseE]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV13AddItemDialog[_ZTV13AddItemDialog]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV13AddItemDialog[_ZTV13AddItemDialog]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AddItemDlg.o:(.rodata._ZTV13AddItemDialog[_ZTV13AddItemDialog]+0x460)||undefined reference to `wxTopLevelWindowGTK::OnInternalIdle()'|
Release/AutoHARP/src/AddSkillDlg.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddSkillDlg.o:(.rodata._ZTV11AddSkillDlg[_ZTV11AddSkillDlg]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AddSkillDlg.o:(.rodata._ZTV11AddSkillDlg[_ZTV11AddSkillDlg]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AddSkillDlg.o:(.rodata._ZTV11AddSkillDlg[_ZTV11AddSkillDlg]+0x460)||undefined reference to `wxTopLevelWindowGTK::OnInternalIdle()'|
Release/AutoHARP/src/AddSubSkillDlg.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddSubSkillDlg.o||In function `wxArrayString::Item(unsigned long)':|
/usr/include/wx-3.0/wx/arrstr.h|177|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/arrstr.h|177|undefined reference to `wxTrap()'|
Release/AutoHARP/src/AddSubSkillDlg.o:(.rodata._ZTV15GetSubSkillsDlg[_ZTV15GetSubSkillsDlg]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/AddSubSkillDlg.o:(.rodata._ZTV15GetSubSkillsDlg[_ZTV15GetSubSkillsDlg]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/AddSubSkillDlg.o:(.rodata._ZTV15GetSubSkillsDlg[_ZTV15GetSubSkillsDlg]+0x460)||undefined reference to `wxTopLevelWindowGTK::OnInternalIdle()'|
Release/AutoHARP/src/CDatabaseCls.o||In function `wxArrayString::Item(unsigned long)':|
/usr/include/wx-3.0/wx/arrstr.h|177|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CDatabaseCls.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CDatabaseCls.o||In function `wxArgNormalizer<int>::wxArgNormalizer(int, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|456|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CDatabaseCls.o||In function `wxArgNormalizerWchar<wxString const&>::wxArgNormalizerWchar(wxString const&, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/strvararg.h|532|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CDatabaseCls.o:/usr/include/wx-3.0/wx/arrstr.h|177|more undefined references to `wxTrap()' follow|
Release/AutoHARP/src/CMixedGenresDlg.o:(.rodata._ZTV15CMixedGenresDlg[_ZTV15CMixedGenresDlg]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/CMixedGenresDlg.o:(.rodata._ZTV15CMixedGenresDlg[_ZTV15CMixedGenresDlg]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/CMixedGenresDlg.o:(.rodata._ZTV15CMixedGenresDlg[_ZTV15CMixedGenresDlg]+0x460)||undefined reference to `wxTopLevelWindowGTK::OnInternalIdle()'|
Release/AutoHARP/src/CNPCGeneratorDlg.o||In function `wxArrayString::Item(unsigned long)':|
/usr/include/wx-3.0/wx/arrstr.h|177|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CNPCGeneratorDlg.o||In function `wxRound(double)':|
/usr/include/wx-3.0/wx/math.h|135|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/math.h|135|undefined reference to `wxTrap()'|
/usr/include/wx-3.0/wx/math.h|135|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CNPCGeneratorDlg.o||In function `wxArgNormalizer<int>::wxArgNormalizer(int, wxFormatString const*, unsigned int)':|
/usr/include/wx-3.0/wx/strvararg.h|456|undefined reference to `wxTrap()'|
Release/AutoHARP/src/CNPCGeneratorDlg.o:/usr/include/wx-3.0/wx/strvararg.h|456|more undefined references to `wxTrap()' follow|
Release/AutoHARP/src/CNPCGeneratorDlg.o:(.rodata._ZTV10wxScrolledI7wxPanelE[_ZTV10wxScrolledI7wxPanelE]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/CNPCGeneratorDlg.o:(.rodata._ZTV10wxScrolledI7wxPanelE[_ZTV10wxScrolledI7wxPanelE]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
Release/AutoHARP/src/CNPCGeneratorDlg.o:(.rodata._ZTV16CNPCGeneratorDlg[_ZTV16CNPCGeneratorDlg]+0x140)||undefined reference to `wxWindowBase::SetVirtualSizeHints(int, int, int, int)'|
Release/AutoHARP/src/CNPCGeneratorDlg.o:(.rodata._ZTV16CNPCGeneratorDlg[_ZTV16CNPCGeneratorDlg]+0x220)||undefined reference to `wxWindowBase::MakeModal(bool)'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
Online research says I might need wxUSE_UNICODE. So I tried that with no results. Does anyone know what the disconnect might be here by looking at the undefined references? Thanks!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Building a project on ubuntu - will not link - undefined reference

Post by doublemax »

wxTrap() should not be visible in release mode. This looks like the libs were built in release mode, but the application uses debug mode.
Use the source, Luke!
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

Thanks for the reply. So I looked into how I was compiling deeper. I do not have any debug information going into the compilation. I have nothing checked in the Compiler flags for Release Mode as well in the global mode. I do have the debugging flags checked for the debug mode. I am compiling in Release mode. Here is the wx-config --cflags.

Code: Select all

-I/usr/local/lib/wx/include/gtk2-unicode-3.1 -I/usr/local/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread
wx-config --libs

Code: Select all

-L/usr/local/lib -pthread   -lwx_gtk2u_xrc-3.1 -lwx_gtk2u_webview-3.1 -lwx_gtk2u_stc-3.1 -lwx_gtk2u_richtext-3.1 -lwx_gtk2u_ribbon-3.1 -lwx_gtk2u_propgrid-3.1 -lwx_gtk2u_aui-3.1 -lwx_gtk2u_gl-3.1 -lwx_gtk2u_html-3.1 -lwx_gtk2u_qa-3.1 -lwx_gtk2u_adv-3.1 -lwx_gtk2u_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1
This was what I used to compile wxWidgets

Code: Select all

../configure --enable-unicode --enable-webview --enable-release
I realize that --enable-unicode and --enable-release are default but I added them just to be sure that it was compiled that way.

I still get the errors above. As far as I can tell everything seems to be right. However I do noticed the -D in my wx-config --cflags and I am hoping those do not mean debug. If so, then that is weird.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidHart »

Hi,
However I do noticed the -D in my wx-config --cflags
You mean '-D__WXGTK__ -pthread' etc? Those are D for 'defined'.

What are the (relevant) settings in C::B's compiler and linker fields? Do you invoke wx-config direct there (as you should), or have you inserted its output?
If the former, are you sure the correct wx-config is being called? (Hint: look at the Build output.) If the latter, is it still correct?

Regards,

David
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

I actually inputted the results for wx-config --libs all into the linker settings and just have wx-config --cflags in the compiler settings. I will double check but at first glance it seemed to be correct and match what I get from the terminal. However I will make sure that is the case here and report back.
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Building a project on ubuntu - will not link - undefined reference

Post by coderrc »

whats your actual full linker command look like?
I'd venture a guess that you are listing wxwidgets too soon. It might be worth a try just wrapping your libs with -Wl,--start-group and -Wl,--end-group
on the otherhand maybe the library link order is perfect, but you are listing your objects _after_ the libraries [-X
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

I noticed that I am using compiler flags that are for 3.0 and linker flags that are for 3.1. I'm not sure how that happened. I have conflicting results with wx-config --cflags. After further testing I don't think my application is ready for 3.1 so I am going to go back to 3.0. Hopefully that was the issue and all will work well now. I will report back on my findings.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Building a project on ubuntu - will not link - undefined reference

Post by ONEEYEMAN »

BTW, you need to change to use the "--cxxflags".
"--cxxflags" option is for C++ code and it is more appropriate.

Thank you.
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

I can try that as well.

Currently I am getting a Terminated on status 127. I understand what this means however there is no additional information from Code::Blocks that tells me why I am getting status 127. According the site FAQ it could be a invalid PATH or a typo. I checked my global settings to make sure I am pointing to the right wxWidget directory. So this is where I am right now. I'm further, but stuck on a status 127 with no message about why.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Building a project on ubuntu - will not link - undefined reference

Post by ONEEYEMAN »

Hi,
Mixing up the library version might b e a possibility.
But why not just enter `wx-config --cxxflags` in the project settings dialog?

Thank you.
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

using wx-config --cflags vs wx-config --cxxflags makes no difference. They both return the exact same thing. It appears everything is compiling and linking... however it terminates on a status 127 with nothing to say why it terminated on status 127. Does anyone have a few ideas to explore on why I might be getting a status 127 exit code?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidHart »

using wx-config --cflags vs wx-config --cxxflags makes no difference
In this instance that's true. But in the long term it's better to do things in the officially-correct way, otherwise you risk future breakages.
however it terminates on a status 127
I presume you're now talking about running the program, rather than building it. http://tldp.org/LDP/abs/html/exitcodes.html suggests
"command not found" 'illegal_command' "Possible problem with $PATH or a typo"

Does the program seem to work? What happens if you run it in a terminal outside C::B, and afterwards check the exit code with
'$?'
Is that also 127? If not, it's probably something internal to C::B.

Otherwise try running the program in your debugger.
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

I tried to run the application by just double clicking the actual application in the folder window. It won't start up. I haven't tried to use the terminal to run it. That's an interesting alternative to try. Didn't think of that. I have tried the debugger. Actually that was the first thing I tried hoping it would tell me where it was terminating. It terminates quickly, it doesn't even break in the application anywhere. So it seems it terminating right after linking but before it even runs the first line of code. I saw the exit code meaning and sometimes the ide will give you a clue, however since Code::Blocks doesn't tell me, a bad Path or typo is very cryptic.

I will try the terminal and see if the results are different. From what I can tell, all paths are correct. If there is a typo, I'm unsure as to where that typo is. This should be pretty easy. I never had this kind of complication before. I kinda wish I didn't erase my last ubuntu environment. :(
DavidKlecker
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 232
Joined: Sun Nov 29, 2009 10:35 am

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidKlecker »

I have a couple more clues that might help:

1) when I actually just use `wx-config --libs all` in my linker build options I get the following error "/usr/bin/ls: cannot find -lwx_gtk2u_media3.0" Now this is interesting because if I just put it the actual value for wx-config --libs all I do not see this error, or the error isn't reported. Looking into this I figured maybe I didn't install the dev libraries for wxWidgets in Ubuntu. So I ran sudo apt-get install libwxgtk3.0-dev. It said I already have it. So I have the correct development libraries installed, yet error continues to come up. Strange

2) If I run from the terminal it will actually say that the library for webview doesn't exist even though that library it is trying to find is clearly there. The exact error it returns is "error whileloading shared libraries: libwx_gtk2u_webview-3.0.so.0: cannot open shared object file: No suc file or directory.". Well that's not true because I open up /usr/local/bin and the file in question is right there. The only explanation I have is that Code::Blocks is not linking to that directory? I find that hard to believe if it is getting the rest of the libraries and files that are located there. Maybe it's not and this is the first of many libraries and/or files it is trying to find.

This could be a Code::Blocks issue so I am creating a thread over there as well.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Building a project on ubuntu - will not link - undefined reference

Post by DavidHart »

So I have the correct development libraries installed, yet error continues to come up
Do:
sudo apt-cache search wxgtk
(or look in e.g. synaptic) and you'll see that the media and webview libs and dev packages are separate. You need to install whichever of those that you need and aren't currently installed.
Post Reply