Linker won't find -lglut - c++

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)

Related

recompiling with -fPIE flag could not resolve error

I am trying to compile this app using its makefile on WSL. But I get the following error:
g++ -g -Wall -ansi pendulumSystem.o TimeStepper.o particleSystem.o ClothSystem.o simpleSystem.o camera.o main.o vecmath/src/Vector3f.o vecmath/src/Vector2f.o vecmath/src/Matrix3f.o vecmath/src/Matrix4f.o vecmath/src/Vector4f.o vecmath/src/Quat4f.o vecmath/src/Matrix2f.o -o a3 -L. -lRK4 -lglut -lGL -lGLU
/usr/bin/ld: ./libRK4.a(RK4.o): relocation R_X86_64_32 against symbol `__gxx_personality_v0##CXXABI_1.3' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: ./libRK4.a(RK4.o): relocation R_X86_64_PC32 against symbol `_Znwm##GLIBCXX_3.4' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:15: a3] Error 1
I tried editing my makefile to include the flag like below, but it still gives me the same error message.
INCFLAGS = -I vecmath/include
INCFLAGS += -I /usr/include/GL
LINKFLAGS = -L. -lRK4 -lglut -lGL -lGLU
CFLAGS = -g -Wall -ansi -fPIE
CC = g++
SRCS = $(wildcard *.cpp)
SRCS += $(wildcard vecmath/src/*.cpp)
OBJS = $(SRCS:.cpp=.o)
PROG = a3
all: $(SRCS) $(PROG)
$(PROG): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $# $(LINKFLAGS)
.cpp.o:
$(CC) $(CFLAGS) $< -c -o $# $(INCFLAGS)
depend:
makedepend $(INCFLAGS) -Y $(SRCS)
clean:
rm $(OBJS) $(PROG)
Could it be that the provided libRK4.a file was not compiled with the -fPIE flag?

Compile a c++ program on PC to communicate with DJI phantom 4 pro

I am trying to receive on my PC(linux mint), a streaming from the camera of a DJI phantom 4 using OpenCV.
The example I am following is : https://developer.dji.com/guidance-sdk/documentation/tutorials/index.html (I am following the linux part)
I copied the Copy libDJI_guidance.so in /usr/local/lib and I checked, it is there.
The makefile is :
#define a compiler
CXX = g++
#define target name
TARGET = main
#define dependencies of target
OBJECTS = main.o DJI_utility.o
#define the Include and Library path
CFLAGS = -g -Wall -I/usr/local/include -I../../../include
LDFLAGS = -Wl,-rpath,./ -lpthread -lrt -L./ -L/usr/local/lib/ -lDJI_guidance -lusb-1.0 `pkg-config --cflags --libs opencv`
$(TARGET) : $(OBJECTS)
$(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS)
main.o : main.cpp DJI_utility.h
$(CXX) $(CFLAGS) -c main.cpp DJI_utility.h
DJI_utility.o : DJI_utility.cpp DJI_utility.h
$(CXX) $(CFLAGS) -c DJI_utility.cpp DJI_utility.h
clean:
rm -rf *.o *.gch *.avi $(TARGET)
But when i excute a make in the command line i get:
g++ -o main main.o DJI_utility.o -Wl,-rpath,./ -lpthread -lrt -L./ -L/usr/local/lib/ -lDJI_guidance -lusb-1.0 `pkg-config --cflags --libs opencv`
/usr/bin/ld: skipping incompatible /usr/local/lib//libDJI_guidance.so when searching for -lDJI_guidance
/usr/bin/ld: skipping incompatible /usr/local/lib/libDJI_guidance.so when searching for -lDJI_guidance
/usr/bin/ld: skipping incompatible //usr/local/lib/libDJI_guidance.so when searching for -lDJI_guidance
/usr/bin/ld: cannot find -lDJI_guidance
/usr/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status
Makefile:12: recipe for target 'main' failed
make: *** [main] Error 1
The project is located in:
~/Documents/studies_SRT/SRT5/TX_drone/Guidance-SDK/demo/guidance_track
The output of an ls is:
DJI_guidance.h DJI_utility.cpp DJI_utility.h DJI_utility.h.gch DJI_utility.o main.cpp main.o Makefile
Thank you.
You seem to have downloaded library files for the wrong architecture. If you're on a 64-bit system, download the 64-bit version of the libraries.

Trouble compiling fractal animation program Xlib and glut

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.

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

/usr/bin/ld: cannot find : No such file or directory

I'm following this SDL tutorial to try and make use of some SDL extension libraries. My code is identical to theirs but I am still unable to make the file which leads me to believe the problem is in my makefile which looks like this:
CXX = g++
# Update these paths to match your installation
# You may also need to update the linker option rpath, which sets where to look for
# the SDL2 libraries at runtime to match your install
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
SDL_INCLUDE = -I/usr/local/include
# You may need to change -std=c++11 to -std=c++0x if your compiler is a bit older
CXXFLAGS = -Wall -c -std=c++11 $(SDL_INCLUDE)
LDFLAGS = $(SDL_LIB)
EXE = SDL_Lesson3
all: $(EXE)
$(EXE): main.o
$(CXX) $< $(LDFLAGS) -o $#
main.o: main.cpp
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm *.o && rm $(EXE)
That makefile worked fine for previous examples. The only thing that has changed in this example is line 5 where I added -lSDL2_image as per the tutorial. When I try make the file I get the following traceback:
rony#comet:~/Documents/cpp/helloworld/lesson3$ make
g++ main.o -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image -o SDL_Lesson3
/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status
make: *** [SDL_Lesson3] Error 1
Is there an error with my makefile? Have I not installed the library correctly?
The problem is this rogue comma:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
causing the linker to look for libraries in a non-existent directory with an empty name, as well as /usr/local/lib. Removing the comma should fix it.