GLEW libraries seems to have issues when linking - c++

I'm getting really frustrated now with trying to link this glew Library
Here's the build log:
g++ -o test.exe "src\\test.o" -lglew32 -lglfw -lglu32 -lopengl32
src\test.o: In function `main':
C:\dev\test\Debug/../src/test.cpp:31: undefined reference to `_imp__glewInit#0'
C:\dev\test\Debug/../src/test.cpp:41: undefined reference to `_imp____glewGenVertexArrays'
C:\dev\test\Debug/../src/test.cpp:42: undefined reference to `_imp____glewBindVertexArray'
I've tried moving around which libraries go first in the build command.
This seems to be an issue that others on the internet are having but i cant seem to find any of them that have fixed it

Ok I know it's a bit wierd be answering my own question but here was the issue:
Apparently the errors were occuring in two areas
For a starter, i didn't need glu32 only opengl32 as i beleive glew handled this itself
Secondly, for some wierd reason i had to call
#define GLEW_STATIC
manually before I imported

Related

In function `uv__signal_global_init': ... undefined reference to `pthread_atfork'

I'm using libUV in my project and I'm getting the following error when I'm linking...
In function `uv__signal_global_init': ... undefined reference to `pthread_atfork'
The strange thing is, my project only fails to link on certain flavors of Linux, but works on MacOS and Windows.
Any idea how to resolve this error?
After scouring the internet, I found the solution in an obscure post from Ben Noordhuis in a Google group post.
#tl;dr
Link with -luv -ldl -lrt -pthread (in that order or it'll break when
-W,--as-needed is in effect.)

Cygwin OpenGL compiling returns undefined references to imp_iob

I'm attempting to compile this tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/ with Cygwin. I'm getting the following errors:
$ g++ main.cpp -o main -lm -lgl -lglut -lglew -lglfw -lopengl32 -lglu32 -lglaux
-lodbc32 -lodbccp32
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11a0): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11c8): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x11f0): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1394): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1661): undefined reference to `_imp___iob'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o):win32_windo
w.c:(.text+0x1696): more undefined references to `_imp___iob' follow
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: /usr/lib/gc
c/i686-pc-cygwin/4.7.3/../../../libglfw.a(win32_window.o): bad reloc address 0x0
in section `.rdata'
collect2: error: ld returned 1 exit status
What may be causing this?
When you see unresolved symbols to _imp__, it implies you are trying to link against a library that was built to use a DLL at run-time. Technically, the problem is how the MSVC compiler mangles the import stub for __stdcall functions - it pre-fixes an underscore, which gcc is not expecting (e.g. _imp instead of imp).
cygwin/MinGW needs a little bit of extra help (either they must use a library that was compiled with gcc or the MSVC DLL-based import library must be altered). There is an article that explains this here.
However, the vast majority of the time the simpler solution is simply to link against the static linking version of your library. In the case of GLEW and glfw, they both ship with static libraries. You will need to define GLEW_STATIC and link against glew32s instead of glew. As for glfw, I am not as familiar - consult the documentation for glfw to find out how to do this.

How to use GLEW with MinGW [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I was trying to use glew32.lib file to link in my project, than I compile Glew source by myself to get glew.a file. Now, I have these link errors in my project:
g++ -o Chapter10(OpenCLTest).exe src\Chapter10(OpenCLTest).o -lopengl32 -lglew -lglut32 -lglu32 -lopencl
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x167): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x39a): undefined reference to `_imp__glewInit'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x3a7): undefined reference to `_imp__glewIsSupported'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x48a): undefined reference to `_imp____glewGenBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x495): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x4dd): undefined reference to `_imp____glewBufferData'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x50b): undefined reference to `_imp____glewGetBufferParameteriv'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d67): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d7f): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d95): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1dad): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x2078): undefined reference to `_imp____glewBindBuffer'
collect2: ld returned 1 exit status
It is good to solve this problem but by the way I want to ask are there any other opengl implementaions of gl extentions?
I'm afraid you can't use glew.lib with g++ (because .lib is a proprietary Microsoft format). These errors you get are missing function entry points, meaning that you didn't compile GLEW correctly (the required functions are not exported in your .so - need to know more details in order to be able to solve this issue).
As for the other part of the question, you can try GLEH. It is still in the development phase and may need some tweaking to work for you, but we've been using it quite successfuly in linux so it shouldn't be too bad.
(I know this is a bit late, but I figured it might solve someone else's problem, so) I had a very similar problem compiling a program that linked to GLEW dynamically. It turns out that I had overlooked the libglew32.dll.a file - that also needed to be present (in addition to libglew32.a and glew32.dll that I had previously copied to my project folder.)
You could try GLee which essentially does the same thing as GLEW.
Strange nobody has said anything about this. By default on Windows, the GLEW headers use declspec(dllimport) for all of the external functions, which mangles all of their names. This is why all of the missing external symbol names all have _imp____ at the front.
If you wan't to use a static build of GLEW (you mentioned something about libglew.a), define GLEW_STATIC during the build of GLEW and during the build of your application. This will unmangle the names for static linking.
If you want to link to a shared library version of GLEW, make sure to build GLEW with GLEW_BUILD. I'm not sure if this is necessary with gcc but it is if the library is built with MSVC.
Furthermore, the GNU toolchain actually supports Microsoft's .lib format for linking. source
You may find it easiest to just compile GLEW yourself or even include it in your project. It is only one source file and a few headers. To compile the library manually, use something along the lines of gcc -shared -o libGLEW.dll -Wl,--out-implib=libGLEW.dll.a -O2 -DGLEW_BUILD glew.c. To get the static version use something like gcc -c -O2 -DGLEW_STATIC glew.c instead.

Linking error when upgrading from lua 4.0.1 to 5.1.4

I'm working on a really old source code (compiled in Red Hat). Before it had lua-4.0.1 so I just compiled the latest lua (lua-5.1.4) and installed it in the same directory as the old one. The implementation isn't very big so there wasn't much to change except a few function names and I had to include "lauxlib.h" to get it to compile. It compiles without any problems but it gives these linking errors.
/usr/local/lib/liblua.a(loadlib.o): In function `ll_load':
loadlib.o(.text+0x19): undefined reference to `dlopen'
loadlib.o(.text+0x2a): undefined reference to `dlerror'
/usr/local/lib/liblua.a(loadlib.o): In function `ll_sym':
loadlib.o(.text+0x52): undefined reference to `dlsym'
loadlib.o(.text+0x63): undefined reference to `dlerror'
/usr/local/lib/liblua.a(loadlib.o): In function `ll_unloadlib':
loadlib.o(.text+0x8): undefined reference to `dlclose'
Basically all the paths are correct but I use the same flags for the compiler as the old one, I havent changed the makefile at all.
-static -lpthread -lnsl -lutil -ldl -lmysqlclient -llua -llualib -lz -lcppunit
The ldl flag is already there.
I just want to know things to try. Everything is appreciated. This is driving me insane.
Place -ldl at the end of the liner command. The order is important.
The linker searches for libraries fulfilling an unreferenced symbol only in libs which are standing more right on the command line. Your new liblua.a now uses dlopen and friends, while the older didn't. Since -ldl is left of -llua, the linker does not use libdl to link the lua references.

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries I need to include.
I currently have "opengl32", "fltk_gl", "glu32", and "fltk" included (-l), each of which seem to reduce the number of errors. I compiled FLTK using make with no specified options. Including all of the produced library files doesn't fix the problem, and I'm convinced that it's just some Windows specific problem.
Compile log:
**** Build of configuration Debug for project CG5 ****
make all
Building target: CG5.exe
Invoking: Cygwin C++ Linker
g++ -o"CG5.exe" ./src/draw_routines.o ./src/gl_window.o ./src/my_shapes.o ./src/shape.o ./src/shapes_ui.o ./src/tesselation.o -lopengl32 -lfltk_z -lfltk_gl -lglu32 -lfltk
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x197): undefined reference to `_SelectPalette#12'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x1a7): undefined reference to `_RealizePalette#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x1fe): undefined reference to `_glDrawBuffer#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x20d): undefined reference to `_glReadBuffer#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x23a): undefined reference to `_glGetIntegerv#8'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x2c3): undefined reference to `_glOrtho#48'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x2f3): undefined reference to `_SwapBuffers#4'
...and lots more
Thanks a ton for the help.
EDIT: These first few lines are obviously OpenGL related, although I'm still not sure what additional libraries need to be included.
Just a guess: your makefile was written for Linux, and on Cygwin some libraries are either missing or in a different place. You're going to have to examine the makefile, locate the missing libraries, and either move the libs to where the makefile expects them or change the makefile to look in the right place.
The libraries it needs are listed on the line starting g++ (prepend 'lib' to the names after the -l flags)
Sorry for the lack of closure, but I just booted into my Linux netbook and got it working.
-lfltk -lfltk_gl -lGLU -lGL -lXext -lX11 -lm