Linker errors on compiling openGL samples 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.
Post Reply
gridlock
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jan 03, 2006 4:13 pm

Linker errors on compiling openGL samples

Post by gridlock » Thu Mar 01, 2007 4:02 pm

Hello, i use wxwidgets 2.8.0 with gcc 3.4.2 on a winxp sp2 computer, i am getting linker errors when i try to compile any projects that require wxGlCanvas.

I set USE_OPENGL = 1 in the file config.gcc before compiling wxwidgets; I have also set wxUSE_GLCANVAS to 1 int the lib/msw/wx/setup.h file, before attempting to compile the samples.

All the other samples compile fine. This happens whether I build wxwidgets statically or as a shared library. see the error message below.

Code: Select all

windres --use-temp-file -i../../../samples/sample.rc -ogcc_msw\isosurf_sample_rc.o   --define __WXMSW__         --include-dir .\..\..\..\lib\gcc_lib\msw --include-dir ./../../../include --include-dir .  --include-dir ./../../../samples
g++ -c -o gcc_msw\isosurf_isosurf.o  -O2 -mthreads  -DHAVE_W32API_H -D__WXMSW__         -I.\..\..\..\lib\gcc_lib\msw -I.\..\..\..\include -W -Wall -I.  -I.\..\..\..\samples -DNOPCH   -Wno-ctor-dtor-privacy   -MTgcc_msw\isosurf_isosurf.o -MFgcc_msw\isosurf_isosurf.o.d -MD isosurf.cpp
g++ -o gcc_msw\isosurf.exe gcc_msw\isosurf_sample_rc.o gcc_msw\isosurf_isosurf.o   -mthreads -L.\..\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows  -lwxmsw28_gl -lopengl32 -lglu32     -lwxmsw28 -lwxtiff -lwxjpeg -lwxpng  -lwxzlib  -lwxregex -lwxexpat    -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
gcc_msw\isosurf_isosurf.o(.text+0x8b7):isosurf.cpp: undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)'
gcc_msw\isosurf_isosurf.o(.text+0x8eb):isosurf.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
gcc_msw\isosurf_isosurf.o(.text+0x947):isosurf.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
gcc_msw\isosurf_isosurf.o(.text+0x1071):isosurf.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
gcc_msw\isosurf_isosurf.o(.text+0x1a17):isosurf.cpp: undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)'
gcc_msw\isosurf_isosurf.o(.text+0x1a4b):isosurf.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
gcc_msw\isosurf_isosurf.o(.text+0x1aa7):isosurf.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
gcc_msw\isosurf_isosurf.o(.text+0x1b75):isosurf.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
gcc_msw\isosurf_isosurf.o(.text+0x1c7c):isosurf.cpp: undefined reference to `wxGLCanvas::SwapBuffers()'
gcc_msw\isosurf_isosurf.o(.text+0x1d15):isosurf.cpp: undefined reference to `wxGLCanvas::OnSize(wxSizeEvent&)'
gcc_msw\isosurf_isosurf.o(.text+0x1d40):isosurf.cpp: undefined reference to `wxGLCanvas::SetCurrent()'
gcc_msw\isosurf_isosurf.o(.rdata$_ZTV12TestGLCanvas[vtable for TestGLCanvas]+0x8):isosurf.cpp: undefined reference to `wxGLCanvas::GetClassInfo() const'
gcc_msw\isosurf_isosurf.o(.rdata+0x0):isosurf.cpp: undefined reference to `wxGLCanvas::sm_eventTable'
gcc_msw\isosurf_isosurf.o(.text$_ZN12TestGLCanvasD1Ev[TestGLCanvas::~TestGLCanvas()]+0x13):isosurf.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
gcc_msw\isosurf_isosurf.o(.text$_ZN12TestGLCanvasD0Ev[TestGLCanvas::~TestGLCanvas()]+0x14):isosurf.cpp: undefined reference to `wxGLCanvas::~wxGLCanvas()'
collect2: ld returned 1 exit status
make: *** [gcc_msw\isosurf.exe] Error 1


User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Thu Mar 01, 2007 5:24 pm

Considering that you have "-lwxmsw28_gl" in your flags, and it's not complaining about not being able to find it, it's obvious that you do in fact have that setup correctly. But other than pointing that out, I can't think of any reason it's not working. Your next step might be to do a symbol lookup on the wxmsw28_gl lib (something like "nm wxmsw28_gl.so.??? | grep wxGLCanvas") and see if it is in fact missing these symbols, and if it is, you must still be missing the appropriate GL configuration options while compiling the wxWidgets libraries. I wouldn't suspect setup.h since your application uses it as well to determine if GL support is built in, and your project is correctly enabled for GL since otherwise you wouldn't be getting these undefined reference errors.

gridlock
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jan 03, 2006 4:13 pm

Post by gridlock » Thu Mar 01, 2007 5:56 pm

The output of nm goes like this:

Code: Select all

c:\>nm c:\wxwidgets\lib\gcc_lib\libwxmsw28_gl.a

gllib_dummy.o:
00000000 b .bss
00000000 d .data
00000000 t .text

gllib_glcanvas.o:
00000000 b .bss
00000000 d .data
00000000 t .text

Apparently, this library is empty! I have no idea what could have gone wrong, is it possible that nothing was compiled in?
Remember, programming is like sex: one mistake and you have to support it for the rest of your life

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Thu Mar 01, 2007 6:26 pm

gridlock wrote:Apparently, this library is empty! I have no idea what could have gone wrong, is it possible that nothing was compiled in?
Yes, and that appears to be the case then. How are you compiling wxWidgets? What options are you using?

gridlock
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jan 03, 2006 4:13 pm

Post by gridlock » Thu Mar 01, 2007 7:10 pm

I downloaded the wxMSW installer for windows, and the only modifications I made to the extracted files are the changes to ($WXDIR)\build\msw\config.gcc:

Code: Select all

BUILD = release
MONOLITHIC = 1
USE_ODBC = 1
USE_OPENGL = 1
OFFICIAL_BUILD = 1
Every other setting is at defaults.
Remember, programming is like sex: one mistake and you have to support it for the rest of your life

gridlock
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jan 03, 2006 4:13 pm

Post by gridlock » Fri Mar 02, 2007 12:11 am

Thanks tierra, I have found the cause of the error: the makefile process did not define wxUSE_GLCANVAS.

Looking through the sources ($WXDIR)\src\msw\glcanvas.cpp, lines 18 to 664, the wxGLCanvas definition is surrounded by a preprocessor directive,

Code: Select all

#if wxUSE_GLCANVAS
and since the makefile copies the default setup.h (which defines wxUSE_GLCANVAS=0) from the source dir to the lib/gcc_lib/wx directory BEFORE compilation and IMMEDIATELY included in the build process, wxUSE_GLCANVAS never gets defined and the entire wxGLCanvas class is skipped during compilation!

I corrected the issue by modifying the following lines in the default ($WXDIR)\build\msw\makefile.gcc (I added -DwxUSE_GLCANVAS)

line 1137, inside the definition of GLDLL_CXXFLAGS:

Code: Select all

-DWXUSINGDLL -DwxUSE_GLCANVAS=1 -DWXMAKINGDLL_GL $(__RTTIFLAG) $(__EXCEPTIONSFLAG) \
line 1149, in the definition of GLLIB_CXXFLAGS:

Code: Select all

-DwxUSE_GLCANVAS=1 $(__RTTIFLAG) $(__EXCEPTIONSFLAG) -Wno-ctor-dtor-privacy $(CPPFLAGS) \
I am surprised i havent seen anybody bring this issue up, since the library was releaed in december! Doesnt anybody use the wxGLCanvas with wx 2.8?
Remember, programming is like sex: one mistake and you have to support it for the rest of your life

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Mar 02, 2007 1:22 am

I have no idea how things work on windows, but in mac and linux i just pass a --with-opengl flag and it takes care of everything automatically, no need to manually edit files. Though windows is not unix so things might be different there...

gridlock
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jan 03, 2006 4:13 pm

Post by gridlock » Fri Mar 02, 2007 7:15 am

I just went through the FAQs now and I noticed that it was mentioned that you have to edit setup.h if you need GLCanvas; this is not very clear, though.

I found out the hard way that despite the fact that the program authors say you should not change the definitions in ($WXDIR)\include\wx\msw\setup.h, but to change them in the created/copied one (lib\gcc_lib\wx\setup.h), this rule does not hold for GLCanvas: you have to edit the source BEFORE you compile.

But the problem is solved and i can compile my GL apps now. Thanks all.
Remember, programming is like sex: one mistake and you have to support it for the rest of your life

ask
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Jul 29, 2007 3:39 pm

What else can be checked?

Post by ask » Sun Jul 29, 2007 3:51 pm

gridlock wrote:But the problem is solved and i can compile my GL apps now. Thanks all.
I faced the same problem as you did in January, but I got problems further. As you pointed about *.cpp file I took off the #define at all in order not to get a void library *.a after compiling the library with OPENGL. As a result I've successfully compiled the libray and succesfully built the "penguin" opengl expamle. 0 errors and so on. But when I start it - program closes automaticaly. When I debug it - it's faild at ->ShowWindow(). I tried to build the rest opengl examples and the same result - build ok, run - open and exit with no notice of error.

The rest explamples for wxwidgets built and run just fine with no problem at all. But opengl does not want. Can you suggest anything what else can be done to solve the problem?

I use WinXP Home SP2, the latest CodeBlocks, MinGW 3.2.0-rc3 and wxwidgets 2.8.3.

Post Reply