I have used openGL with glut before and SDL2 on its own before. Now I try to make an optimized project with Glew, SDL2 and OpenGL. I want it to be able to run on Linux(I mainly use Debian),OSX and Windows. So I tried to write my own makefile. This code should only create a window for me.
Im developing on osx.
I have only my main.cpp, Display.cpp and Display.h
This is what i tried:
#my compiler
CC=g++
#my program name
PRGNAME=booom
#library search directory
LIBDIR=-L/usr/lib -L/usr/local/lib
#library names
#uses libSDL.a, libGLEW.a
LIBNAME=-lSDL -lGLEW
#includes for libraries
INCLUDES=-I/usr/include -I/usr/local/include
#my compiler options
CFLAGS=-c -Wall
all: main.o Display.o
$(CC) $(CFLAGS) $(INCLUDES) $(LIBDIR) $(LIBNAME) -o $(PRGNAME) main.o Display.o
#main.cpp is the dependency of main.o
main.o: main.cpp
$(CC) $(CFLAGS) $(INCLUDES) $(LIBDIR) $(LIBNAME) main.cpp
Display.o: Display.cpp
$(CC) $(CFLAGS) $(INCLUDES) $(LIBDIR) $(LIBNAME) Display.cpp
clean:
rm -rf *o booom
I get a main.o and a Display.o file, but i don't get an executable.
When I do "make clean && make" this is my output:
macbook-mehrschwein:Booom Mehrschwein$ make clean && make
rm -rf *o booom
g++ -c -Wall -I/usr/include -I/usr/local/include -L/usr/lib -L/usr/local/lib -lSDL -lGLEW main.cpp
clang: warning: -lSDL: 'linker' input unused
clang: warning: -lGLEW: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/lib'
clang: warning: argument unused during compilation: '-L/usr/local/lib'
g++ -c -Wall -I/usr/include -I/usr/local/include -L/usr/lib -L/usr/local/lib -lSDL -lGLEW Display.cpp
clang: warning: -lSDL: 'linker' input unused
clang: warning: -lGLEW: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/lib'
clang: warning: argument unused during compilation: '-L/usr/local/lib'
g++ -c -Wall -I/usr/include -I/usr/local/include -L/usr/lib -L/usr/local/lib -lSDL -lGLEW -o booom main.o Display.o
clang: warning: -lSDL: 'linker' input unused
clang: warning: -lGLEW: 'linker' input unused
clang: warning: main.o: 'linker' input unused
clang: warning: Display.o: 'linker' input unused
clang: warning: argument unused during compilation: '-Wall'
clang: warning: argument unused during compilation: '-I /usr/include'
clang: warning: argument unused during compilation: '-I /usr/local/include'
clang: warning: argument unused during compilation: '-L/usr/lib'
clang: warning: argument unused during compilation: '-L/usr/local/lib'
macbook-mehrschwein:Booom Mehrschwein$
The problem is in -c flag that you use in all stages.
It means to compile an object file but not to link.
Remove it for your all target. Like:
all: main.o Display.o
$(CC) $(LIBDIR) $(LIBNAME) -o $(PRGNAME) main.o Display.o
This fixed the problem with linking.
Now ensure that you have libSDL in the folders you specify.
new version with:
all: main.o Display.o
$(CC) $(LIBDIR) $(LIBNAME) -o $(PRGNAME) main.o Display.o
main.o: main.cpp
$(CC) $(CFLAGS) $(INCLUDES) main.cpp
Display.o: Display.cpp
$(CC) $(CFLAGS) $(INCLUDES) Display.cpp
no warnings for Display.o and main.o anymore.
the error that i get now:
g++ -c -Wall -I/usr/include -I/usr/local/include main.cpp
g++ -c -Wall -I/usr/include -I/usr/local/include Display.cpp
g++ -Wall -I/usr/include -I/usr/local/include -L/usr/lib -L/usr/local/lib -o booom main.o Display.o -lSDL -lGLEW
ld: library not found for -lSDL
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
EDIT: The name is libSDL2.a, not libSDL.a
but now it tells me that he can't find libGlew.a
libGLEW.a is in /usr/lib
libSDL2.a is in /usr/local/lib
do they both need to be in the same directory?
EDIT2:
Update
I changed a few things, i now build GLEW into "/usr/local", so everything is in the same dir.
my makefile:
#my compiler
CC=g++
#my program name
PRGNAME=booom
#library search directory
LIBDIR=-L/usr/local/lib
#library names
#uses libSDL2.a, libGLEW.a
LIBNAME=-lSDL2 -lGLEW
#includes for libraries
INCLUDES=-I/usr/local/include
#my compiler options
CFLAGS=-c -Wall
all: main.o Display.o
$(CC) $(LIBDIR) $(LIBNAME) -o $(PRGNAME) main.o Display.o
#main.cpp is the dependency of main.o
main.o: main.cpp
$(CC) $(CFLAGS) $(INCLUDES) main.cpp
Display.o: Display.cpp
$(CC) $(CFLAGS) $(INCLUDES) Display.cpp
clean:
rm -rf *o booom
my error now:
rm -rf *o booom
g++ -c -Wall -I/usr/local/include main.cpp
g++ -c -Wall -I/usr/local/include Display.cpp
g++ -L/usr/local/lib -lSDL2 -lGLEW -o booom main.o Display.o
Undefined symbols for architecture x86_64:
"_glClear", referenced from:
Display::Clear(float, float, float, float) in Display.o
"_glClearColor", referenced from:
Display::Clear(float, float, float, float) in Display.o
"_glCullFace", referenced from:
Display::Display(int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Display.o
"_glEnable", referenced from:
Display::Display(int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Display.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
seams like i got a 32-bit version, while i need a 64-bit version, but i have build that on my own, and don't really know what i have done wrong. normally you also have do do something like ./config before building. but there is no config for GLEW. the only solution that i found on google involves macports, but i would love to do it without macports
Related
I'm still learning how to set up a Makefile and I'm kind of lost here. I'm using windows and currently trying to fire up my Makefile for small C++ SDL project.
I have 3 .cpp files:
main.cpp
window.cpp
rect.cpp
As well as 2 extra header files:
Window.h
rect.h
So having trouble setting up everything on a Makefile
This is what i currently have:
CXXFLAGS = -Ideps/include -std=c++0x
LXXFLAGS = -Ldeps/lib -lmingw32 -lSDL2main -lSDL2
cup: main.o
g++ main.o -o cup $(LXXFLAGS)
main.o: main.cpp
g++ main.cpp -c $(CXXFLAGS)
window.o: window.cpp
g++ window.cpp -c
rect.o: rect.cpp
g++ rect.cpp -c
But I'm getting a bunch of undefined reference errors for my constructors on my command prompt.
Help please!
From the Makefile contents I read that cup binary is only created from main.o and it does not link window.o nor rect.o, which is where probably those missing references are defined. At the very least I would update the primary rule to say:
cup: main.o window.o rect.o
g++ $(LXXFLAGS) -o cup $^
Thus said, you could make even more use from implicit rules that are built into make, and, if following the standard naming for linking flags, the Makefile could be reduced even further to just a linking line (as compilation rules are implicit), e.g.:
$ cat Makefile
CXXFLAGS = -Ideps/include -std=c++0x
LDFLAGS = -Ldeps/lib
LDLIBS = -lmingw32 -lSDL2main -lSDL2
cup: main.o window.o rect.o
$(LINK.cc) $^ $(LDLIBS) -o $#
Output:
$ make
g++ -Ideps/include -std=c++0x -c -o main.o main.cpp
g++ -Ideps/include -std=c++0x -c -o window.o window.cpp
g++ -Ideps/include -std=c++0x -c -o rect.o rect.cpp
g++ -Ideps/include -std=c++0x -Ldeps/lib main.o window.o rect.o -lmingw32 -lSDL2main -lSDL2 -o cup
I'm trying to write Makefile for my project.
Here is the file structure:
Makefile:
CXXFLAGS = -ISDL2/include -std=c++11
LXXFLAGS = -lSDL2/lib/x86 -lSDL2main -lSDL2 -lSDL2_image
main.exe: main.o BoardField.o ChessPiece.o Game.o
g++ main.o BoardField.o ChessPiece.o Game.o -o main.exe $(LXXFLAGS) -std=c++11
main.o: main.cpp
g++ main.cpp -c $(CXXFLAGS)
BoardField.o: BoardField.cpp
g++ BoardField.cpp -c $(CXXFLAGS)
ChessPiece.o: ChessPiece.cpp
g++ ChessPiece.cpp -c $(CXXFLAGS)
Game.o: Game.cpp
g++ Game.cpp -c $(CXXFLAGS)
And I get these errors:
g++ main.o BoardField.o ChessPiece.o Game.o -o main.exe -lSDL2/lib/x86
-lSDL2main -lSDL2 -lSDL2_image -std=c++11 c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lSDL2/lib/x86
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lSDL2main
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lSDL2
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lSDL2_image
Where is the problem?
-lSDL2/lib/x86 is incorrect. You use the lower-case -l option, which is used to add a library to link with, not a path to search for libraries.
To add a path use the upper-case -L option: -LSDL2/lib/x86
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.
I am trying to include a sqlite3 in my cpp project but while compilation it gives below error:
g++ -c -std=c++11 -g src/Main.cpp -I"C:/Mycode/src/DB"
-L"C:/Mycode/src/DB" -lsqlite3
g++ -g -o Main.exe Main.o Data.o SqliteApi.o -lws2_32
-L"C:/Mycode/src/DB" -lsqlite3
C:/Mycode/src/DB/sqlite3.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: ***[Mycode.exe] Error 1
I feel during final linking time it gives error.
I am using my own make file for compilation, below is the make command I am using:
DB_DIR="C:/Mycode/src/DB"
clean:
rm Main.o Main.exe
Main.exe: Main.o Data.o SqliteApi.o
g++ -g -o Main.exe Main.o Data.o SqliteApi.o -lws2_32 -L${DB_DIR} -lsqlite3
Main.o: src/Main.cpp
g++ -c -std=c++11 -g src/Main.cpp -I${DB_DIR} -lsqlite3
Data.o: src/Data.cpp
g++ -c -std=c++11 -g src/Data.cpp
SqliteApi.o: src/SqliteApi.cpp
g++ -c -std=c++11 -g src/SqliteApi.cpp
I have googled but I couldn't find any solution or suggestion for this error.
Any help will be much appreciated.
The recommended way of using the SQLite library is to compile the amalgamation source file directly into your program:
Main.exe: Main.o Data.o SqliteApi.o
g++ -g -o Main.exe Main.o Data.o SqliteApi.o sqlite3.o -lws2_32
sqlite3.o: src/sqlite3.c
gcc -c ... src/sqlite3.c
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