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'm using Fedora 16. I've installed freeglut and freeglut-devel packages. I tried to rum a simple opengl program, but i'm getting the following error
gcc cube.c -o cube -lglut
/usr/bin/ld: /tmp/ccSFol4w.o: undefined reference to symbol 'gluLookAt'
/usr/bin/ld: note: 'gluLookAt' is defined in DSO /usr/lib/libGLU.so.1 so try adding it to the linker command line
/usr/lib/libGLU.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
Compile : g++ sampleCode.cpp -lglut -lGL -lGLU
run : ./a.out
is your answer.
You have to link some gl libraries.
g++ cube.c -o cube -I /usr/lib/libglut.so.3 /usr/lib/libGL.so.1 /usr/lib/libGLU.so.1 -lGL
I think you should consult some introduction text on compilers, linkers and libraries, i.e. how the pieces come together when building a program. In essence the linker is telling you, that there are some loose ends and it cannot finish linking the program due to them. Adding a library happens by the -l switch with library name (GLU in your case), not by giving it a full path to the library file.
do what it says
gcc cube.c -o cube -lglut -lGLU
I got the exact same problem in Ubuntu 12.04 LTS when I wrote:
g++ square.cpp -lglut
But then I found on the web that some people also added -lGL and lGLU so I did it and it compiles now:
g++ square.cpp -lglut -lGL -GLU
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I am compiling code that uses the external library https://www.cs.cmu.edu/afs/cs/project/quake/public/www/triangle.html.
All the triangle source and object files are in ~/triangle/ folder. So I compile like this:
g++ -g sobel_aot_run.cpp sobel_x_out.a sobel_y_out.a support.a -ljpeg -lpng -std=c++11 -I ../include -I ../tools -I ~/triangle -lpthread -ldl -o sobel
Even though I have specified -I ~/triangle, running this command gives the following error:
/tmp/cc9AUEre.o: In function `main':
/home/zendevil/Halide/tutorial/sobel_aot_run.cpp:74: undefined reference to `triangulate(char*, triangulateio*, triangulateio*, triangulateio*)'
collect2: error: ld returned 1 exit status
How to compile this?
-I only specifies to the compiler that you are searching in a directory for files to satisfy #include statements.
You now need to compile and link to the triangulate code that you are using.
I'm trying to add caffe to an existing project. I get 99 undefined reference errors, suggesting that it has something to do with linking libraries. The errors mention caffe, boost and google (relates to gflags or glog).
Linker command: (libcaffe is in /home/torcs/lib)
g++ main.o linuxspec.o -L/home/torcs/export/lib -lopenal -lalut -lvorbisfile -L/usr/lib -L/home/torcs/lib -lracescreens -lrobottools -lclient -lconfscreens -ltgf -ltgfclient -ltxml -lplibul -lraceengine -lmusicplayer -llearning -lplibjs -lplibssgaux -lplibssg -lplibsm -lplibsl -lplibsg -lplibul -lglut -lGLU -lGL -lpng -lz -ldl -lXrandr -lXrender -lXxf86vm -lXmu -lXi -lXt -lSM -lICE -lXext -lX11 -lm -lcaffe -lglog -o torcs-bin
Linker error (first 2 and final 2):
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::FillerParameter::_default_type_'
/home/torcs/export/lib/librobottools.so: undefined reference to `void caffe::caffe_gpu_set<float>(int, float, float*)'
...
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::NetStateRule::NetStateRule()'
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::Timer::MilliSeconds()'
collect2: error: ld returned 1 exit status
I added -lcaffe and tried libcaffe.a and libcaffe.so separately but the number of errors is not decreasing as I add libraries. If I misspel -lcaff it says cannot find libcaffe, which it doesn't do otherwise, so the lib is included correctly I guess.
I read up on linker order (windows background) and found that the symbols only get added if they are on the required symbols list. More specific libs should be last, dependent libs should be first. I figured that if I only add lcaffe at the end, the unrecognized symbol list should be populated, and at least the caffe symbols would be recognized, and maybe replaced by other dependencies. But that doesn't happen.
I tried to find whether libcaffe supplies the references. For the final undefined reference (caffe::Timer::MilliSeconds()), nm libcaffe.a finds:
0000000000188090 T _ZN5caffe5Timer12MilliSecondsEv
0000000000187910 T _ZN5caffe8CPUTimer12MilliSecondsEv
Which suggest the reference is in the lib. But the undefined reference error doesn't go away.
I also tried adding boost libs and glog, didn't help.
Edit. There is some additional weird behaviour going on. I think it is unrelated, but am not sure. The first time I build after a make clean I get an error about include <random>:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
This prevents the o files and librobottools.so from getting built. But if I make again, the c++11 error disappears, this lib does get build, and I see the 99 undefined reference errors.
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 download GLFW source code. Next correct compile with sudo make install, after that library is installed in /usr/local , now when I create project in code blocks I can include GLFW/glfw3.h, but when I try to complie i have errors
How to correct add this library ?
Every time I must write this command to terminal: " g++ -std=c++0x main.cpp -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread" , is any posiibility to automatize linking and compilation with Code::Blocks ?
Just click :
Project -> Build Options
And then just add liked libs. Of course widouth - sign. And you must remember that there are Debug Release and both. So you must enter names of those libs in good target.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I'm starting to learn OpenGL with Redbook version 4.3 and I need some linking help (I think). I am running Linux Mint and a Radeon HD 5000/6000/7350/8350 Series video card. I'm trying to compile and link the first program (triangles.cpp). I installed freeglut3, freeglut3-dev, libxi-dev, glew-utils, and libglew-dev. I found this linking command in an old version of OpenGL Superbible and I'm guessing I need to add -lGLEW.
g++ triangles.cpp -lX11 -lXi -lglut -lGL -lGLU -lGLEW
I get the following error:
/tmp/ccXSL2nx.o: In function `init()':
triangles.cpp:(.text+0x11d): undefined reference to `LoadShaders'
collect2: error: ld returned 1 exit status
I copied over vgl.h and LoadShaders.h and LoadShaders.cpp from the Redbook's source code download. What else am I missing?
Try this:
g++ triangles.cpp LoadShaders.cpp -lX11 -lXi -lGL -lGLU -lGLEW -lglut -o triangles
This will compile and link both triangles.cpp and LoadShaders.cpp into a single output file triangles.
Note, too, that you might not need "-lX11 -lXi". To test this try:
g++ triangles.cpp LoadShaders.cpp -lGL -lGLU -lGLEW -lglut -o triangles
Also note that the order of libraries is important.
When linking a project I am working on, the linker gives the following errors:
/usr/bin/ld: ../Includes and Libs/lib/libsfml21rca.a(SoundFile.o): undefined reference to symbol 'sf_read_short##libsndfile.so.1.0'
/usr/bin/ld: note: 'sf_read_short##libsndfile.so.1.0' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so so try adding it to the linker command line
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so: could not read symbols: Invalid operation
The thing is, libsndfile.so is already linked before libsfml21rca.a, so I have no idea where the problem is.
I'm using Code::Blocks 10.05
Thanks for help in advance
EDIT:
Here is the linking command:
g++ -L"Includes and Libs/lib" -L"Includes and Libs/lib/raknet3_731" -L"Includes and Libs/lib/d3d_new/x86" -L"Includes and Libs/lib/ogg" -L"Includes and Libs/lib/sdl" -LBullet/lib -o (filename) ...(a whole lot of object files) -lGLEW -lglfw -lGL -lGLU -lpthread -lopenal -ljpeg -lfreetype -lsndfile -lXrandr -lsfml-system -lsfml-window -lsfml-audio ../Bullet/lib/LinearMath.lib ../Bullet/lib/BulletCollision.lib ../Bullet/lib/BulletDynamics.lib "../Includes and Libs/lib/raknet3_731/RakNetLibStaticDebug.lib" "../Includes and Libs/lib/libsfml21rca.a" ../../../../../../home/msabol/Desktop/SFML/sfml2st/sfmlVideo/sfmlVideo/bin/Release/libsfmlVideo.a ../../../../../../home/msabol/Desktop/SFML/sfmlVideo/bin/Release/libsfmlVideo.a
The linker only runs one pass over the library files. So if you have something in Library A that needs something in Library B, you need to have g++ objects... -llibA -llibB, if you use g++ objects... -llibB -llibA it will fail in the manner you show.
So, in your case, put the -lsndfile after "../Includes and Libs/lib/libsfml21rca.a".
(And whose idea was it to put spaces in a the "Includes and Libs" directory - not the best idea I've seen...)