When I am compiling simple examples it works with the following compiler instructions, but I don't understand them in detail:
clang -o name name.cpp -L/usr/local/lib -lglfw -lGLEW -framework OpenGL
I understand the -o flag for the executable file and also the -L flag which clarifies where the compiler should search for libraries to use.
But when it comes to the -lglfw or -lGLEW flags I have no idea what they do. Same for the -framework flag, but there I have an idea what it does.
Also what is the difference between OpenGL, GLEW and GLUT?
Related
This is very strange or very simple. I am using Devil library and in the very simple program I have to initialize it by:
ilInit();
iluInit();
And here is the problem. IlInit() works fine, but iluInit() is not! It can not find the reference.
Of course I include headers:
#include <IL/il.h>
#include <IL/ilu.h>
And compile my file by:
g++ -std=gnu++11 -O3 myIL.cpp -lglfw3 -lGL -lGLEW -lIL -lGLU -lX11 -lXxf86vm -lpthread -lXrandr -lXi -o myIL
(generally I want to use Devil lib for OpenGL project but I don't think it is important right now).
I have also all headers in /usr/include/IL and *.a, *.so etc. files in /usr/lib/x86_64-linux-gnu.
Btw it also be great if someone could explain me what the difference between IlInit(), iluInit() and ilutInit(). I cannot find the simple explanation.
I don't know anything about devils, but I suspect you forgot to link against the relevant library -- wouldn't that be libILU.so, i.e. require the compiler/loader option -lILU?
I'm trying to cross-compile a small test opengl/glew program and I get linker errors from undefined references.
$ /usr/bin/i486-mingw32-g++ -I/usr/i486-mingw32/include -L/usr/i486-mingw32/lib/ -lglfw -lglew32 -lopengl32 main.cc
/tmp/cct8OpVh.o:main.cc:(.text+0x50): undefined reference to `glfwInit'
/tmp/cct8OpVh.o:main.cc:(.text+0xa6): undefined reference to `glfwOpenWindowHint'
...
The same code does work when compiling for linux:
$ g++ -I/usr/include -L/usr/lib/ -lglfw -lGLEW -lGL main.cc
One thing that caught my eye is that every exported symbol from cross-compiled libraries has an extra underscore prefix:
$ nm /usr/lib/libglfw.a | grep glfwInit$
00000000 T glfwInit
$ /usr/i486-mingw32/bin/nm /usr/i486-mingw32/lib/libglfw.a | grep glfwInit$
00000000 T _glfwInit
This seems to be a common thing since even libstdc++.a shares this property, but why is my cross-compiler linker then looking for non-underscore symbols?
Running arch with following packages (local means AUR):
community/mingw32-binutils 2.23.1-3
community/mingw32-gcc 4.7.2-1
local/mingw32-glew 1.9.0-1
local/mingw32-glfw 2.7.7-1
community/mingw32-pthreads 2.9.1-1
community/mingw32-runtime 3.20-4
community/mingw32-w32api 3.17-1
EDIT
After playing out with both pkg-config and watching glfw recompile and test itself, I came up with the following magic that seems to work, at least I'm compiling:
/usr/bin/i486-mingw32-g++ -I/usr/i486-mingw32/include -L/usr/i486-mingw32/lib -mwindows main.cc -lglew32 /usr/i486-mingw32/lib/libglfw.a /usr/i486-mingw32/lib/libopengl32.a -static-libgcc
There are few questions though:
What is the difference between linking with -l and without?
Why do I need to use -l with glew and cannot with glfw
I was able to solve my problem and, in case someone ever runs into similar situation hope this helps you.
There are two versions of glew32 -library in my system, glew32.a and glew32.dll.a.
glew32.a does not allow for using --static, glew32.dll.a does.
The two commands which compile succesfully, only first of which I've run are:
/usr/bin/i486-mingw32-g++ -I/usr/i486-mingw32/include -L/usr/i486-mingw32/lib main.cc -lglew32.dll -lglfw -lopengl32 --static
/usr/bin/i486-mingw32-g++ -I/usr/i486-mingw32/include -L/usr/i486-mingw32/lib main.cc -lglew32 -lglfw -lopengl32
Looking at my old compiling attempts, the problem was wrong order of libraries and that main.cc was after the libraries.
There is a program, called pkg-config that helps you to configure your compiler. See the manual pages for usage information, but, for this case, its output is:
-mwin32 -I/usr/i486-mingw32/include -L/usr/i486-mingw32/lib -lglfw -lglu32 -lopengl32 -lm -s -mwindows -e _mainCRTStartup
Try to compile with this, I guess it will work.
I've recently made the decision to re-write some OpenGL code for a game using im working on using non depreciated techniques. Instead of drawing primitives with glBegin() and glEnd(), i'm trying to stick to vertex array objects and such. I'm trying to get code to compile from http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/ . I've done alot of linking before but for some reason this isn't working. I'm trying to link GLEW to my project with CodeBlocks as my IDE and MinGW GCC as my compiler. How do I go about fixing this? Yes, i did link "glew32.lib"
This usually happens if you link GLEW statically, but don't inform the header about this to happen. For this you must define the preprocessor token "GLEW_STATIC". This is best done as a compiler option. In case of GCC, add -DGLEW_STATIC to your compiler command line.
Try this:
pkg-config --libs --static glew
in the terminal. Then, copy the libs it gives you and paste after your gcc/g++ statement:
g++ <your-file-name>.cpp -o <output-file-name> -lGL -lGLU -lglfw3 -lrt -lm -ldl -lXrandr -lXinerama -lXcursor -lXext -lXrender -lXfixes -lX11 -lpthread -lxcb -lXau -lXdmcp -lGLEW -lGLU -lGL -lm -ldl -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp
(some are repeated above because I used glfw too)
This is supposed to solve your problem, because usually these libraries are not declared.
If you use Linux, FLTK ui library with OpenGL, see .../bin/fltk-config file for LDLIBS. It should contain also "-lGLEW" or you can add this option to the LDLIBS parameter when compile. Of course "libglew-dev" should be installed.
I'm working on a collaborative project and the guy who controls the master branch of the project works on a mac. Because of this, there are a few minor differences in his makefile that don't translate well to me on Windows. I use MinGW to hold my libraries, and compile using g++.
Makefile (as I thought it should go)
bomb: source/Level.cpp source/Level.h source/main.cpp
g++ -o bomb source/Level.cpp source/main.cpp -Wall -I. -I\MinGW\include\SDL -lSDLmain -lSDL -lSDL_image
The Makefile that works for him:
bomb: source/Level.cpp source/Level.h source/main.cpp
g++ -o bomb source/Level.cpp source/main.cpp -Wall -I. -I/Library/Frameworks/SDL.framework/Headers -lSDLmain -lSDL -lSDL_image -framework
My include files for the SDL library are at "C:\MinGW\include\SDL". Using that knowledge, how would I correctly write the makefile? As a side note, the error I get when using my current makefile is:
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to 'WinMain#16'
Have you tried adding -lmingw32 to the end of the libraries list? And do you have a int main(int argc, char** argv) function defined somewhere? Also, see the SDL FAQ
I'm trying to find the compiler flag for linking GLX on a Linux based system. So far, I have (in qt Creator):
unix:LIBS += -lglx -lX11 -lGLEW -lGLU -lGL -lXext -L/usr/X11R6/lib
But, that still gives me glxChooseVisual was not declared in this scope, thus preventing my code from compiling.
When defining a glX function, the 'X' must be capitalized. That was my fault for not seeing that. Consider this problem solved.