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?
Related
I am trying to compile a sample code in the 9th edition of "OpenGL Programming Guide" using NetBeans v8.1 on Ubuntu 14.04 64bit x86. The sample code is triangles.cpp, the first sample code of the book, downloadable from here. I have added information in the "Linker" tab of Project Properties dialog as follows:
You can see that "Additional Library Directories", "Libraries" and "Additional Options" fields are filled with needed and correct information (at least I think so).
However, when I build the project by clicking the "Clean and Build Project" button in the IDE, I got tons of errors:
g++ -c -g -I/home/me/ComputerGraphics/include -I/home/me/glfw-3.2.1/include -MMD -MP -MF "build/Debug/GNU-Linux/01-triangles.o.d" -o build/Debug/GNU-Linux/01-triangles.o 01-triangles.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/opengl1 build/Debug/GNU-Linux/01-triangles.o -L/home/me/glfw-3.2.1/bin/lib -Wl,-rpath,/home/me/glfw-3.2.1/bin/lib -lglfw3 -pthread -ldl -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11
build/Debug/GNU-Linux/01-triangles.o: In function `init()':
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:27: undefined reference to `gl3wGenVertexArrays'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:28: undefined reference to `gl3wBindVertexArray'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:35: undefined reference to `gl3wCreateBuffers'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:36: undefined reference to `gl3wBindBuffer'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:37: undefined reference to `gl3wBufferStorage'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:46: undefined reference to `LoadShaders'
......
I had previously thought it is related to vulkan but now I have added -ldl and the errors persist. So, how can I successfully compile the triangles.cpp code on linux within NetBeans? Thank a lot.
It turns out I need one more library GL3W in addition to GLFW. Follow these steps (based on the settings I have set already in NetBeans):
(1) Go to https://github.com/shakesoda/gl3w to install GL3W, or use existing files shipped with the book.
(2) Set the linker flag to:
-pthread -ldl -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -lXcursor
Note: the -ldl and -lXcursor flags are not mentioned in previous threads but indeed needed.
(3) Add gl3w.c and LoadShaders.cpp to the Source Files
(4) Add #include <cstdio> at the beginning of LoadShaders.cpp
(5) Compile and done!
For an entry level program, I'm currently compiling with
g++ manip.c -o manip -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -ldl -lXinerama -lXcursor -lGLEW
It was a very time-consuming process of trial and error figuring out which flags were necessary, googling the 'undefined references to', copy pasting every flag I came across and then deleting flags one by one until I had removed those I didn't need.
For a beginner who is learning the ropes, compiling example programs in tutorials (that don't have instructions on how to compile), is there a way to automatically link everything the program might need? Perhaps a way to move the libraries so they don't have to be explicitly linked?
If not, is there a way to simplify the flag adding process? (I can envisage the command becoming incredibly long from all the flags as the program grows in complexity.)
I'm writing this answer for someone at the level I'm at.
You apparently can write makefiles that will automatically detect what libraries should be linked. The syntax for doing so is way out of my depths, but I'll edit this in future if I advance to that.
To simplify the compiling option, you could write a makefile that links every single library you might need. The example I've included below has the libraries I've found out I require so far and may need to be extended significantly as I develop the OpenGL program further.
Call the file 'Makefile'. Run it using the command make.
So
vim Makefile
Inside the file, I have this:
manip: manip.c
g++ manip.c -o manip -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -ldl -lXinerama -lXcursor -lGLEW -lglfw3 -lGL -lm -lXi
The term before the : on the first line will be the output executable. The term after the : on the first line is the C/C++ file the executable depends on. The next line is what the Makefile will execute if it detects the source code (after : on the first line) has changed.
If you have a more extensive set of files that depend on each other, you can add them below with the same syntax (google this if relevant to you).
So I now edit the manip.c file, run the command make, and manip is generated for me.
I have spent all day trying to resolve this issue and now am looking for a bit of help.
My global Linker settings:
-lGL -lGLU -lpthread -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -l/usr/lib/libglfw.sso
I have two projects, one is a library used by the other.
When I compile Project A, it compiles into a library without issue. When i compile Project B, while also linking to the library created by Project A, I get the error in the title.
the compiler command is(called from Project B)(libEngine.a is the result of Project A):
g++ -L/usr/lib -o bin/Debug/Game obj/Debug/main.o obj/Debug/src/MyScene.o -lGL -lGLU -lpthread -lXrandr -lXxf86vm -lXi -lXinerama -lX11 ../Engine/bin/Debug/libEngine.a /usr/lib/libglfw.so
Any help would be appreciated.
Is libGL.so file or link present in /usr/lib? If yes. then check the pressence/architecture of the (lib) file pointed by the link. I hope this will solve the issue.
This was aswered by Gyapti jain, there was a missing link to the actual location of the library. the missing link belonged in /usr/lib, the library was in /usr/library/nvidia-331
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.