Compiling error: cannot find -lGLU and -lGL in kubuntu linux - c++

I have some problems with compiling "hello world" application in kubuntu linux 11.10. This is project file:
// opengltext.pro
SOURCES += \
main.cpp
QT += opengl
And one cpp file:
// main.cpp
#include <QApplication>
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
return app.exec();
}
i have got the following errors:
:-1: error: cannot find -lGLU
:-1: error: cannot find -lGL
:-1: error: collect2: ld returned 1 exit status
I try find in google the solution of this problem. But didn't find.
i try to install:
sudo apt-get install libglw1-mesa-dev
but this error is still taking place
What's the problem?

You need the following 2 packages:
xlibmesa-gl-dev
xlibmesa-glu-dev
-- edit --
Thanks for correction #ephemient, these were obsolete names, right names are:
libgl1-mesa-dev
libglu1-mesa-dev

In addition to the the answer about installing the right libraries (sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev) you may need to add:
unix:LIBS += -L/usr/lib/x86_64-linux-gnu/mesa/
to your .pro file, I know I needed to. Of course that path may be different if your using 32bit software or other system dependant reasons.

Related

unidentified reference to glutInit

I tried to compile a basic OpenGL program, simply just a blank window.
I'm using CodeLite with the g++ compiler on Linux Mint 18.1 (Ubuntu 16.04 LTS).
The code so far is:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(int argc, char **argv)
{
glutInit(&argc, argv);
printf("hello world\n");
return 0;
}
At first my compiler (G++ in CodeLite) gave the error
/home/USER/Projects/CodeLite/Graphical/main.cpp:7: undefined reference to `glutInit'
I downloaded all the up to date GLEW and GLUT includes from their respective websites and unpacked them to /usr/include/GL, I edited the project settings linker like this.
Now it gives the error message:
/usr/bin/ld: cannot find -lglut
Makefile:4: recipe for target 'All' failed
What can I do to fix this?
You should install the libraries from the package manager instead: libglew-dev, freeglut3-dev, libgl1-mesa-dev and libglu1-mesa-dev. The includes and binary files will be placed in the appropriate location.
If the linker cannot find the .so files, locate them with dpkg -L freeglut3-dev and add this directory in the linker command line
g++ -L/path/to/libglut.so *.o -o programname

OpenCV 3.1 Upgrade Leads to Linker Errors on Linux

I've recently upgraded from OpenCV 2.4.11 to OpenCV 3.1 by following this guide. This sudo make install seems to have worked successfully and when I run pkg-config --modversion opencv, I get the appropriate version (3.1.0).
But for some reason, I am now running into linker errors, and even simple programs are unable to compile, for example:
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char* argv[])
{
Mat im1 = imread(argv[1]);
return 0;
}
returns the errors:
main.cpp:-1: error: undefined reference to cv::imread(cv::String const&, int)
main.cpp:-1: error: undefined reference to `cv::String::allocate(unsigned long)'
main.cpp:-1: error: undefined reference to `cv::String::deallocate()'
:-1: error: collect2: error: ld returned 1 exit status
Could this be due to conflicts with the previous installation? Before I go through and start manually deleting files in /usr/local/ [lib | include | bin], I thought I'd ask here first. Any suggestions?
Your linker path is probably wrong. Make sure the opencv you want is the first one on your linker path, or it may link against the wrong one. Deleting opencv2 would probably solve the problem... consider using a package manager in future so you don't have messes like this to contend with all the time.
I went ahead and took the nuclear option (sudo rm followed by sudo make install), and everything compiles now. I'm not proud of this, nor do I necessarily advocate it, but if anyone else reaches this point of desperation, you may find this kill log helpful:
sudo rm -r /usr/share/opencv
sudo rm -r /usr/share/OpenCV/
sudo rm -r /usr/local/include/opencv
sudo rm -r /usr/local/bin/opencv*
sudo rm -r /usr/local/share/OpenCV/
sudo rm -r /usr/local/lib/libopencv_*
sudo rm /usr/local/lib/pkgconfig/opencv.pc
sudo rm /usr/local/lib/python2.7/dist-packages/cv2.so

Can't access SDL library when trying to compile using g++

I'm getting started with SDL -- that is, I have no experience and am basically just trying to get something to compile at this point.
I have a basic program:
#include "sdl/SDL.h"
int main(){
// Fire up SDL, this starts all subsystems; audio video etc.
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
// Now Shut it down
atexit(SDL_Quit);
return 0;
}
And I have this which I'm typing into the terminal:
g++ 'sdl-config --cflags --libs' -o sdltest sdltest.cpp
where sdltest.cpp is the name of the file.
This gives me the error:
g++: error: stl-config --cflags --libs: No such file or directory
Now, previously I have (I think) installed SDL like so:
sudo apt-get install libsdl2-dev
The issue might have to do with a faulty installation -- this might not be the package I was supposed to install, or I might be completely forgetting a step here.
I'm using Ubuntu, and compiling using g++, if it wasn't apparent from context.

Undefined reference to `OGRRegisterAll'

I am trying to write a gdal program to read shapefiles but I don't seem to be able to get past registering the drivers. Here is the code, I'm not sure why the functions in the header files are not available my source file even after including it.
#include "/usr/include/gdal/ogrsf_frmts.h"
int main()
{
GDALAllRegister();
}
If I run this: g++ demo.cpp, I get the following error:
demo.cpp: In function int main():
demo.cpp:6:21: error: GDALAllRegister was not declared in this scope
GDALAllRegister();
^
If I try the c version, I'm getting this:
#include "/usr/include/gdal/ogr_api.h"
int main()
{
OGRRegisterAll();
return 0;
}
gcc create.c
/tmp/cc3YB8sO.o: In function main:
create.c:(.text+0x11): undefined reference to OGRRegisterAll
collect2: error: ld returned 1 exit status
UPDATE
I am using Ubuntu 15.04 64bit
I installed all the packages using the apt:
sudo apt-get install gdal-bin libgdal-dev build-essential
I also have the ubuntugis ppa added and I have qgis 2.10 installed which is from the qgis repo and not from the ubuntugis ppa.
Thank you all for the help, the issue was the linker was not able to find the gdal library.
i did this for the C code
gcc create.c -lgdal

Error while building app in cross-compiled qt in raspberry

I'm trying to build and app on a cross-compiled qt5 in a raspberry pi.
This app is based on this rf24l01 library. When I compile a cpp program from the RPi, everything works fine, but when I tried from my pc running ubuntu 12.04 (32bits) the following error is through:
error: cannot find -lrf24-bcm
I point to the library using this line in the pro file:
LIBS += -L/mnt/rpi/usr/local/lib -lrf24-bcm
AFAIK, this is the path where the lib is located:
This is the result of `ls /mnt/rpi/usr/local/lib:
librf24-bcm.so libwiringPiDev.so libwiringPi.so.2.0
librf24-bcm.so.1 libwiringPiDev.so.2.0 python2.6
librf24-bcm.so.1.0 libwiringPi.so python2.7
Finally, this is the appeared error in detail:
/home/atron/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link,/mnt/rpi/opt/vc/lib -Wl,-rpath-link,/mnt/rpi/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,/mnt/rpi/lib/arm-linux-gnueabihf --sysroot=/mnt/rpi -Wl,-rpath,/usr/local/opt/lib -o homekit main.o -L/mnt/rpi/usr/local/lib -lrf24-bcm -L/mnt/rpi/usr/local/opt/lib -lQt5Network -L/usr/local/opt/lib -lQt5Core -lpthread
/home/atron/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lrf24-bcm
collect2: error: ld returned 1 exit status
What I`m doing wrong?
Thanks in advance,
I don't know if this is "technically" correct, but solved my problem.
The main idea is create a symbolic link of the library to my pc /usr/local/lib folder:
sudo ln -s /mnt/rpi/usr/local/lib/librf24-bcm.so /usr/local/lib/librf24-bcm.so
sudo ln -s /mnt/rpi/usr/local/lib/librf24-bcm.so.1 /usr/local/lib/librf24-bcm.so.1
sudo ln -s /mnt/rpi/usr/local/lib/librf24-bcm.so.1.0 /usr/local/lib/librf24-bcm.so.1.0
Then, on QT creator *pro file you only need to add the lib reference:
LIBS=-lrf24-bcm
I hope this could help to some newbie like me.
Regards,