Cannot build Box2D on Linux: linker error - c++

I'm trying building Box2d v2.3.1 on my Ubuntu (13.10) machine. This is what I'm doing:
$ premake4 gmake
$ cd Build/gmake/
$ make
But the testbed is not building correctly. I get lots of undefined reference errors for glfw and glew symbols, like this:
obj/Debug/Testbed/Main.o: In function `main':
/home/mostafa/.adobe/box2d-2.3.1/Box2D/Build/gmake/../../Testbed/Framework/Main.cpp:458: undefined reference to `glfwCreateWindow'
I have the development packages for both glfw and glew installed. I also checked the Testbed.make makefile and, since I saw no reference to glfw, added -lglfw to the two places where LIBS variable was defined. But I still get the same error.

I managed to fix this at last, after lots of searching and tweaking. This is what I did:
Make sure you have the very latest version of premake. I had to install premake 4.4 (beta version).
Compile and install the latest version of glfw (3.0.4 at the moment) from source. The version in Ubuntu's repositories does not work.
Make sure you have glew and xorg development packages. I installed these from Ubuntu's repository: sudo apt-get install libglew-dev xorg-dev
After running premake4 gmake in Box2D directory, go to Build/gmake and edit Testbed.make. Change the line LIBS += $(LDDEPS) -lX11 -lGL -lGLU -lglut into this LIBS += $(LDDEPS) -lX11 -lGL -lGLU -lglut -lGLEW -lglfw3 -lX11 -lXxf86vm -lpthread -lXrandr -lXi.
Now run make.

Related

Problems setting up GLFW on Arch Linux

I use Linux, more specifically, Arch Linux. I wanted to work with OpenGL, so I did the following steps:
First, I downloaded the glfw-x11 with the pacman package manager.
I also used cmake to add glfw to /usr/local/include, everything works fine.
I wrote a Makefile to run my program with the command:
gcc -o demo main.c -lglfw3 -lm -lXrandr -lXi -lXxf86vm -lpthread
Also note that I removed -lGl because gcc, the compiler, screamed at me.
Here is my project directory: glad main.c Makefile. Note that glad is a directory. And it works fine.
I am running on Linux so I can't install Visual Studio and I am really don't think I need CodeBlocks to create an OpenGL project.
The error the compiler gives me when I run this code (in main.c):
#include <stdio.h>
#include "glad/glad.h"
#include <GLFW/glfw3.h>
int main() {
glfwInit();
printf("Hello, OpenGL!");
// Code goes here..
glfwTerminate();
return 0;
}
The compiler gave me:
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XPending'
/usr/bin/ld: /usr/lib/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Edit
lGL just worked, but still I get the same error.
Another Edit
Adding -ldl, lXinerama and lXcursor worked for me.
Final Edit
I fixed it, first, you create a main.cpp (or whatever you wanna call it). Make sure you have libgl, glu and glfw-x11 installed. Then create a Makefile with the flags -lGL -lGLU -lglfw3 -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread -ldl -lXinerama -lXcursor. Then download glad. Extract glad.zip (Make sure glad is in the project folder). Move src/glad.c into the project directory. Include glad with "include/glad/glad.h" or whatever directory you choose. Also make sure GLFW is in /usr/local/bin.

/usr/bin/ld: cannot find -lGL (Ubuntu 14.04)

I'm trying to build a project created in QT Creator and unfortunately every time I try to compile I get an error. Here is my compiler output:
23:02:20: Running steps for project WallpaperAppQt...
23:02:20: Configuration unchanged, skipping qmake step.
23:02:20: Starting: "/usr/bin/make"
g++ -m64 -o WallpaperAppQt main.o mainwindow.o moc_mainwindow.o -L/usr/X11R6/lib64 -lQt5Widgets -L/usr/lib/x86_64-linux-gnu -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
make: *** [WallpaperAppQt] Error 1
23:02:20: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project WallpaperAppQt (kit: Desktop)
When executing step 'Make'
23:02:20: Elapsed time: 00:00.
You need a package that provides the libGL.so (no version suffix) symlink. In Ubuntu, it's in the libgl1-mesa-dev package. So just do:
sudo apt install libgl1-mesa-dev
I was able to fix my problem by following the instructions in this link:
http://techtidings.blogspot.com/2012/01/problem-with-libglso-on-64-bit-ubuntu.html
(the final two commands)
sudo rm /usr/lib/x86_64-linux-gnu/libGL.so
sudo ln -s /usr/lib/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so
I was having the same problem. Then I used the following command in the terminal:
sudo apt install mesa-common-dev libglu1-mesa-dev"
and the application run perfectly.
It's obvious that ld doesn't find lib GL in default library path which should be include /lib* /usr/lib*. You should install library GL or tell g++ where lib GL was installed with cmd args -L if that was installed already.

Compiling OpenGL program with GLFW3

I installed GLFW3 and am trying to compile my OpenGL program with the following:
g++ -std=c++11 main.cpp -lGL -lGLEW -lglfw3
But here's the library error I get:
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
I also tried with pkg-config:
g++ `pkg-config --cflags glfw3 glew` -o myprog main.cpp `pkg-config --static --libs glfw3 glew`
it compiles but when I run myprog it says it can't find libglfw.so.3
But it is located in /usr/local/lib
http://www.brandonfoltz.com/2012/12/compile-glfw-on-ubuntu-and-fix-libglfw-so-cannot-open-error/
Ubuntu installs libglfw.so.3 in /usr/local/lib so you have to add this line to /etc/ld.so.conf
I had the same problem.
In my case was usefull following steps:
Download glfw source code
unzip it
cd glfw_folder
cmake . (with dot)
make
sudo make install
To check, copy and paste following command in your console "whereis libglfw3".
you should have output like this one: "libglfw3: /usr/local/lib/libglfw3.a" (or another path after ":").
My config: VAIO Pro 13/Ubuntu 16.04 LTS/ Intel HD4000.
P.S.: Yes, I'd tryed "sudo apt-get install libglfw3" and all dependenses.

libmysqlclient_18 not found

I'm trying to connect to mysql with C++ and the MySQLConnector, but I'm getting "undefined reference" errors everytime I make calls to the connector.
example:
/usr/lib/libmysqlcppconn.so: undefined reference to `mysql_stmt_execute#libmysqlclient_18'
My OS is Ubuntu 13.04 VM, I'm using Eclipse CDT and I installed the packages:
sudo apt-get mysql-client
sudo apt-get mysql-server
sudo apt-get mysql-client
sudo apt-get libmysqlclient-dev
I'm wondering that the libs (libmysqlclient,..) are in the folder /usr/lib/x86_64-linux-gnu/
and not in /user/local/mysql/lib like often found on the net. Does this make any difference?
I also downloaded the C++ Connector (binaries) from Oracle and copied the lib directory to /usr/lib and the include directory to /usr/include, but still I'm gettind the undefined reference errors.
I configured Eclipse in a way that I get this compile command:
g++ -L/usr/lib -L/usr/lib/x86_64-linux-gnu -pthread -o "Proj" ./Client.o -lmysqlcppconn -lmysqlclient -lz -lm -ldl
Any ideas?

Problem with glaux.h locating

I try to compile code, that beggins with:
#include<stdlib.h>
#include<GL/gl.h>
#include<glaux.h>
with command:
cc -o test test.c -I/usr/local/include -L/usr/local/lib -lMesaaux -lMesatk -lMesaGL -lXext -lX11 -lm
But one of errors I got is:
test.c:3:18: error: glaux.h: No such file or directory
Then I try:
yum provides glaux.h
but yum find anything.
Before all I installed Mesa with:
yum install mesa*
So, can anyone tell me from where I can get the header file?
Thank you for ahead.
So, I deleted glaux.h from includes (and all functions calls from this header) and successfully compiled with
-lm -lGL
cc keys.