Trouble compiling fractal animation program Xlib and glut - c++

Downloaded the code from this source: http://n.ethz.ch/~vartokb/gl-shaders.html
I run the make file and I get undefined references to xlib and glut libraries. e.g.,
undefined reference to `XOpenDisplay'
undefined reference to `XDefaultScreen'
undefined reference to `glXChooseVisual'
.
.
.
undefined reference to `__glewGenBuffers'
undefined reference to `__glewBindBuffer'
undefined reference to `__glewBufferData'
The compile line looks like this and the makefile is below:
g++ -L/usr/include/GL/ -L/usr/include/X11/ -lm -lrt -lglut -lGLEW -lGL -lGLU -lX11 main.o events.o graphics.o -o gl-shaders
The Makefile:
NAME = gl-shaders
CXX = g++
CXXFLAGS = -O3
LDFLAGS = -L/usr/include/GL/ -L/usr/include/X11/ -lm -lrt -lglut -lGLEW -lGL -lGLU -lX11
SRCS = main.cpp events.cpp graphics.cpp
OBJS = $(SRCS:%.cpp=%.o)
HDRS = config.hpp main.hpp
all: $(NAME)
$(NAME): $(OBJS)
$(CXX) $(LDFLAGS) $(OBJS) -o $(NAME)
.cpp.o:
$(CXX) $(CFLAGS) $(LFLAGS) -c $< -o $#
$(OBJS): $(HDRS)
clean:
rm -f $(OBJS)
rm -f $(NAME)
I have installed Xlib by running:
sudo aptitude install xorg-dev
sudo apt install xorg-dev
sudo apt-get install libx11-dev
And I installed freeglut a while ago. When I list the contents of the directories linked in the makefile I see:
:l /usr/include/GL/
freeglut_ext.h freeglut_std.h glew.h gl.h glu.h glut.h glxext.h glxint.h glxmd.h glxtokens.h wglew.h
freeglut.h glcorearb.h glext.h gl_mangle.h glu_mangle.h glxew.h glx.h glx_mangle.h glxproto.h internal/
and for Xlib:
l /usr/include/X11/
ap_keysym.h Constraint.h DECkeysym.h HPkeysym.h IntrinsicP.h RectObj.h ShellI.h TranslateI.h Xatom.h Xdmcp.h XKBlib.h Xmd.h Xpoll.h Xthreads.h Xwindows.h
bitmaps/ ConvertI.h dri/ ICE/ keysymdef.h RectObjP.h ShellP.h VarargsI.h Xauth.h XF86keysym.h XlibConf.h Xmu/ Xproto.h Xtos.h Xwinsock.h
CallbackI.h Core.h EventI.h ImUtil.h keysym.h ResConfigP.h SM/ Vendor.h Xaw/ Xft/ Xlib.h Xosdefs.h Xprotostr.h Xtrans/
Composite.h CoreP.h extensions/ InitialI.h Object.h ResourceI.h StringDefs.h VendorP.h Xcms.h Xfuncproto.h Xlibint.h Xos.h Xregion.h Xutil.h
CompositeP.h CreateI.h fonts/ Intrinsic.h ObjectP.h SelectionI.h Sunkeysym.h Xalloca.h Xcursor/ Xfuncs.h Xlib-xcb.h Xos_r.h Xresource.h Xw32defs.h
ConstrainP.h cursorfont.h HookObjI.h IntrinsicI.h PassivGraI.h Shell.h ThreadsI.h Xarch.h Xdefs.h X.h Xlocale.h xpm.h xshmfence.h XWDFile.h
Why do I get undefined references when I have all the required files for compilation?

My problem was parameter ordering, as user cyberguijarro points out over here: Linker problems in Ubuntu 11.10
#boto I know that. Actually, the problem was in the parameter order.
Ubuntu 11.10 ships GCC 4.6.1, which apparently introduces stricter
parameter ordering constraints. g++ test.cpp -lX11 works fine. –
cyberguijarro Jan 24 '12 at 9:37
So by changing the compile line from this:
g++ -I/usr/include/GL/ -lglut -lGL -lGLEW -lGLU -I/usr/include/X11/ -lm -lrt -lX11 main.o events.o graphics.o -o gl-shaders
to this:
g++ main.o events.o graphics.o -I/usr/include/GL/ -lglut -lGL -lGLEW -lGLU -I/usr/include/X11/ -lm -lrt -lX11 -o gl-shaders
allowed it to compile.

Related

FLTK - Can't find headers even if I include the correct directory [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I am trying to compile a FLTK project from linux, using the output of the commands:
fltk-config --use-gl --use-images --ldflags
And:
fltk-config --use-gl --use-images --cxxflags
I am using this makefile to compile the project:
I installed the latest FLTK version by just downloading it from fltk.org, and then I compiled and installed it. I also installed X11 and OpenGL. But I still get these errors:
I checked the file system and these headers are in /usr/local/include/FL even if they are not recognized, although I included the directory (-I/usr/local/include) and then in the .cpp and .h files:
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Box.H>
etc...
What could be the problem? do I need to install more libraries?
EDIT
I tried to change the makefile:
CXXFLAGS=-I/usr/local/include -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -I/home/ramy/boost_1_63_0 -std=c++11
LDFLAGS=-L/usr/local/lib -lfltk_images -lfltk_png -lz -lfltk_jpeg -lfltk_gl -lGLU -lGL -lfltk -lXrender -lXcursor -lXfixes -lXext -lXinerama -lpthread -ldl -lm -lX11 -L/home/ramy/boost_1_63_0/lib
SOURCES=Car.cpp Map.cpp CarState.cpp Utilities.cpp CarCollection.cpp TableView.cpp MapView.cpp
OBJECTS=Car.o Map.o CarState.o Utilities.o CarCollection.o TableView.o MapView.o
make:
g++ $(LDFLAGS) $(CXXFLAGS) -c $(SOURCES)
g++ $(LDFLAGS) $(CXXFLAGS) -o ../Evolution table-example.cpp $(OBJECTS)
clean:
rm -f $(OBJECTS) ../Evolution
But I still get the same errors.
Those errors don't mean that you are lacking headers, but libraries.
Here you can read the basis (go down to "Compiling Programs with Standard Compilers").
Basically add -L/usr/local/lib -lfltk -lXext -lX11 -lm to your app compiler command; or use fltk-config --cxxflags.

OpenCL/OpenGL Interop on ARM

i have a small problem with OpenCL/OpenGL interoperability in my code
here's my makefile
LIBS = -lm -lOpenCL -lGAL -lGLEW -lglut -lGLU -lpthread
CFLAGS = -Wall -g
OBJECTS = main.o environment.o input.o animate.o buddhabrot.o buddhacl.o cmodules/timer.o
all: prognonmpi
prognonmpi: $(OBJECTS)
LIBRARY_PATH=/usr/lib/arm-linux-gnueabi/ c++ $(CFLAGS) -o prognonmpi $(OBJECTS) $(LIBS)
%.o: %.cpp $(LIBS)
clean:
rm -f *.o prog cmodules/*.o
the code just comiles fine, but i get a linker error with the following message
LIBRARY_PATH=/usr/lib/arm-linux-gnueabi/ c++ -Wall -g -o prognonmpi main.o environment.o input.o animate.o buddhabrot.o buddhacl.o cmodules/timer.o -lm -lOpenCL -lGAL -lGLEW -lglut -lGLU -lpthread
main.o: In function `displayFunc()':
main.cpp:(.text+0xdda): undefined reference to `clEnqueueAcquireGLObjects'
main.cpp:(.text+0xe12): undefined reference to `clEnqueueReleaseGLObjects'
main.o: In function `initOpenGLBuffers(int, int)':
main.cpp:(.text+0x136a): undefined reference to `clCreateFromGLBuffer'
collect2: ld returned 1 exit status
make: *** [prognonmpi] Error 1
the code compiles very fine on my notebook with the lins, using -lGL instead of -lGAL, seesm -lGAL is ARM specific.
on the ARM machine i get the above mentioned error.
Any suggestions what is missing on my ARM-machine?
using Ubuntu as OS

Installing OpenGL on Ubuntu 13.10

I am a university student trying to setup my home desktop with Ubuntu 13.10 for OpenGL development. I have installed all of these libraries. Our first assignment was to write a simple program and a generic makefile that would work for the rest of the semester. This worked perfectly in the Computer Labs on campus.
My main.c file:
# include <GL/glut.h>
void display();
int main (int argc, char ** argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(640 , 480) ;
glutCreateWindow("Practical 1");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display()
{
glClearColor(0.0 , 0.0 , 1.0 , 1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glFlush();
glutSwapBuffers();
}
And my makefile:
STUDENT_NUMBER = 1234567890
TASK = practical
NUMBER =1
OBJECTS=$(addsuffix .o,$(basename $(shell ls *.C)))
WARNING_FLAGS = -Wall -Wextra -Weffc++ -Winit -self -Wmissing -include -dirs -Wswitch -default -Wswitch -enum -Wunused -parameter -Wstrict -overflow=5 -Wfloat -equal -Wshadow -Wc++0x -compat -Wconversion -Wsign -conversion-Wmissing -declarations -Wstrict -null -sentinel -Woverloaded -virtual -Wsign -promo -Werror -pedantic -Wcast -qual
FORMATTING_FLAGS = -fno -pretty -templates -fmessage -length=80 -fdiagnostics -show -option
CFLAGS = ${WARNING_FLAGS} ${FORMATTING_FLAGS} g -std=c++0x -pipe -frepo
LDLIBS = -lGL -lglut -lGLEW -lGLU -lX11 -lXi -lm -lrt -lpng
LDFLAGS =
CC = g++
TARGET = main
all: ${OBJECTS}
${CC} ${LDFLAGS} ${LDLIBS} $^ -o ${TARGET}
%.o: %.c
${CC} ${CFLAGS} -c ${LDFLAGS} $< -o $#
makefile.dep: *.[Ch]
for i in *.C; do gcc -MM "$${i}"; done > $#
include makefile.dep
clean:
rm ${OBJECTS} *.rpo *.gch makefile.dep ${TARGET}
tar:
make clean; tar -cvjf ${STUDENT_NUMBER}_${TASK}_${NUMBER}.tar.bz2 *
When trying to compile on my home desktop I get these erors:
g++ -lGL -lglut -lGLEW -lGLU -lX11 -lXi -lm -lrt -lpng main.o -o main
main.o: In function `main':
main.C:(.text+0x1e): undefined reference to `glutInit'
main.C:(.text+0x28): undefined reference to `glutInitDisplayMode'
main.C:(.text+0x37): undefined reference to `glutInitWindowSize'
main.C:(.text+0x41): undefined reference to `glutCreateWindow'
main.C:(.text+0x4b): undefined reference to `glutDisplayFunc'
main.C:(.text+0x50): undefined reference to `glutMainLoop'
main.o: In function `display()':
main.C:(.text+0x76): undefined reference to `glClearColor'
main.C:(.text+0x80): undefined reference to `glClear'
main.C:(.text+0x85): undefined reference to `glFlush'
main.C:(.text+0x8a): undefined reference to `glutSwapBuffers'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
I think I might be missing some library or something.
As explained in this question, you need to specify the dependant libraries in after the objects that reference them in your linker command:
g++ main.o -lGL -lglut -lGLEW -lGLU -lX11 -lXi -lm -lrt -lpng -o main
I'm not an expert on makefile syntax, but I think changing the 'all' section of your makefile like this might work:
all: ${OBJECTS}
${CC} ${LDFLAGS} $^ ${LDLIBS} -o ${TARGET}

Undefined reference linking static libSOIL.a on g++ linux

I'm trying to build my openGL project, all worked well until I tried to use the SOIL library (http://www.lonesock.net/soil.html) for loading textures from images. This library comes with a SOIL.h and a libSOIL.a files.
That's what I get when doing make:
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/main.o src/main.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/file_ply_stl.o src/file_ply_stl.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/Proyecto.o src/Proyecto.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/Clock.o src/Clock.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/utils.o src/utils.cpp
...
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/primitives/cilindro.o src/primitives/cilindro.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/primitives/cono.o src/primitives/cono.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -o app -L./lib src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o src/Path.o src/Ant.o src/Tank.o src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL
src/Texture.o: In function `Texture::ini(char const*)':
/home/roger/t/ig/prac/proyecto/src/Texture.cpp:9: undefined reference to `SOIL_load_OGL_texture'
collect2: ld devolvió el estado de salida 1
make: *** [app] Error 1
And that's my Makefile:
TARGET = app
MODULES = src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o
ENGINE = src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o
GAME = src/Path.o src/Ant.o src/Tank.o
PRIMITIVES = src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o
CXX = g++
LIBDIR = ./lib
INCDIR = ./src
LIBS = -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL
LDFLAGS = -L$(LIBDIR)
CXXFLAGS = -I$(INCDIR) -Wl,-rpath,$(LIBDIR) -O3 -g
$(TARGET): $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(LDFLAGS) $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(LIBS)
clean:
rm -f $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(TARGET)
And that's my file hierachy:
.:
lib Makefile src
./lib:
libsfml-audio.so libsfml-graphics.so.2.0 libsfml-system.so.2 libSOIL.a
libsfml-audio.so.2 libsfml-network.so libsfml-system.so.2.0 libSOIL.a.1
libsfml-audio.so.2.0 libsfml-network.so.2 libsfml-window.so libSOIL.a.1.0
libsfml-graphics.so libsfml-network.so.2.0 libsfml-window.so.2
libsfml-graphics.so.2 libsfml-system.so libsfml-window.so.2.0
./src:
Animatable.cpp Clock.cpp Light.cpp Moveable.h random.h TriGeometry.h
Animatable.h Clock.h Light.h Path.cpp Scene.cpp TriIndGeometry.cpp
Ant.cpp Entity.cpp main.cpp Path.h Scene.h TriIndGeometry.h
Ant.h Entity.h main.h Placeable.cpp SFML utils.cpp
Bounded.cpp file_ply_stl.cpp Material.cpp Placeable.h SOIL utils.h
Bounded.h file_ply_stl.h Material.h PlyModel.cpp Tank.cpp Vert.cpp
Camera.cpp Geometry.cpp matrix.h PlyModel.h Tank.h vertex.h
Camera.h Geometry.h Model.cpp primitives Texture.cpp Vert.h
Chess.cpp Graphics.cpp Model.h Proyecto.cpp Texture.h Window.cpp
Chess.h Graphics.h Moveable.cpp Proyecto.h TriGeometry.cpp Window.h
./src/primitives:
...
./src/SFML:
...
./src/SFML/Audio:
...
./src/SFML/Graphics:
...
./src/SFML/Network:
...
./src/SFML/System:
...
./src/SFML/Window:
...
./src/SOIL:
SOIL.h
I don't know what's going on, and why the compiler doesn't find the library file.
I've got #include "SOIL/SOIL.h" in Texture.h and the call to SOIL_load_OGL_texture in Texture.cpp:9, that's the name on the function as defined in SOIL.h. ¿What I am doing bad?
EDIT
I was using the library provided, I compiled it myself and it worked.
I must write down this answer when I compile the SOIL library even the question is asked 4 year ago, because it is so hard to write the CMakeLists.txt myself before I find the CMakeLists.txt.
the CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (SOIL)
set (SOIL_BUILD_TESTS false CACHE BOOL "Build tests")
if(ANDROID)
# Android requires GL ES 2.0 package automatically
set(LIBRARIES GLESv2)
else()
find_package (OpenGL REQUIRED)
include_directories (${OPENGL_INCLUDE_DIR})
set(LIBRARIES ${OPENGL_LIBRARIES})
endif()
file (GLOB SOIL_SOURCES src/*.c)
file (GLOB SOIL_HEADERS src/*.h)
add_library (SOIL ${SOIL_SOURCES} ${SOIL_HEADERS})
target_link_libraries (SOIL ${LIBRARIES})
install (TARGETS SOIL
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install (FILES ${SOIL_HEADERS} DESTINATION include/SOIL)
if (SOIL_BUILD_TESTS)
add_executable (test_SOIL src/test_SOIL.cpp)
target_link_libraries (test_SOIL SOIL)
install (TARGETS SOIL test_SOIL RUNTIME DESTINATION bin)
endif ()

Linker won't find -lglut

SO.
I'm a little new to the Linux dev world (without an ide), so please be patient.
The Issue
I have a make file constructed which compiles about 7-8 files into .o files which are then linked together with a few libraries. I have done locates on these libraries, and their dev counterparts do exist. The problem is that the linker refuses to find them. My output (if I am reading this correctly) tells me that it's looking in the wrong area. I've exported my LD_PATH to include /usr/lib, which is where my .so. files are. My main question is, how do I get -lglew and -lglut to link up with each other? I would also like to put my .o files in my obj folder and my binaries in a bin folder. Is this possible in a makefile? If so, given my make file, what would be the best recipe to do this?
The Makefile
1 BIN = bin/
2 OBJ = obj/
3 TARGET = opengl_03
4 DEPS = main.o displayinit.o initializer.o algorithms.o matrix3f.o window.o vertex3.o
5 CC = g++
6 CFLAGS = -g -m32
7 LIBS = -lglut -lGLEW
8 INCLUDEPATH = -L/usr/include/ -L/usr/lib
9
10 $(TARGET) : $(DEPS)
11 $(CC) $(LIBS) $(INCLUDEPATH) $(CFLAGS) -o $(TARGET) $(DEPS) $(BIN)
12
13 displayinit.o : displayinit.cpp displayinit.h
14 $(CC) -c displayinit.cpp $(OBJ)
15 initializer.o : initializer.cpp initializer.h
16 $(CC) -c initializer.cpp $(OBJ)
17 algorithms.o : algorithms.cpp algorithms.h
18 $(CC) -c algorithms.cpp $(OBJ)
19 matrix3f.o : matrix3f.cpp matrix3f.h
20 $(CC) -c matrix3f.cpp $(OBJ)
21 vertex3.o : vertex3.cpp vertex3.h
22 $(CC) -c vertex3.cpp $(OBJ)
23 window.o : window.cpp window.h
24 $(CC) -c window.cpp $(OBJ)
25 main.o : main.cpp
26 $(CC) -c main.cpp $(OBJ)
27
28 clean:
29 rm $(DEPS)
30
31
Output
g++ -lglut -lGLEW -L/usr/include/ -L/usr/lib -g -m32 -o opengl_03 main.o displayinit.o initializer.o algorithms.o matrix3f.o window.o vertex3.o bin/
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.a when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libglut.a when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.a when searching for -lglut
/usr/bin/ld: cannot find -lglut
/usr/bin/ld: cannot find -lGLEW
/usr/bin/ld: cannot find bin/: File format not recognized
collect2: ld returned 1 exit status
make: *** [opengl_03] Error 1
I appreciate the assistance.
Which Linux are you using? It looks like you're using a 64-bit system, but trying to compile a 32-bit application (because of -m32 compiler switch). So either remove the -m32 or install the 32-bit development libraries. They may be named like freeglut-32bit or something like that.
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
It means ld found libglut.so, but it is not good candidate for -m32 target.
PS, BIN is a dir, why do you put it into compile object?
$(CC) $(LIBS) $(INCLUDEPATH) $(CFLAGS) -o $(TARGET) $(DEPS) $(BIN)