[compiling] Can't link libraries
I have been reading up on this library for a few days now and decided to give it a shot. I am trying to link the libraries, but nothing happens. I am on Ubuntu 16.04, and I have followed the tutorial in the Wiki to install GLFW and OpenAL.
Makefile:
# OBJS specifies which files to compile as part of the project
OBJS = *.cpp
# CXX specifies the compiler that we want to use
CXX = c++
# COMPILER_FLAGS specifies the additional compilation options that we are using
# -w supress all warnings
COMPILER_FLAGS = -w -std=c++11
# INCLUDE_PATHS
INCLUDE_PATHS = -I"/usr/local/include"
# LINKER_PATHS
LINKER_PATHS = -L"/usr/local/lib"
# LINKER_FLAGS
LINKER_FLAGS = -lraylib
# OBJ_NAME specifies the name of our executable
OBJ_NAME = Test
# This is the target that compiles our executable
all: $(OBJS)
$(CXX) $(COMPILER_FLAGS) $(INCLUDE_PATHS) $(LINKER_PATHS) $(LINKER_FLAGS) $(OBJS) -o $(OBJ_NAME)
Errors after compiling:
c++ -w -std=c++11 -I"/usr/local/include" -L"/usr/local/lib" -lraylib *.cpp -o Test
/tmp/cc92J6DK.o: In function `main':
main.cpp:(.text+0x27): undefined reference to `InitWindow'
main.cpp:(.text+0x31): undefined reference to `SetTargetFPS'
main.cpp:(.text+0x36): undefined reference to `WindowShouldClose'
main.cpp:(.text+0x42): undefined reference to `BeginDrawing'
main.cpp:(.text+0x6f): undefined reference to `ClearBackground'
main.cpp:(.text+0xab): undefined reference to `DrawText'
main.cpp:(.text+0xb0): undefined reference to `EndDrawing'
main.cpp:(.text+0xba): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'all' failed
make: *** [all] Error 1
All the libraries are in the lib folder, and the include file is in the include folder.
It seems it's not linking with libraylib.a... and I also see you're not linking with all required libs... To verify it, try copying libraylib.a and raylib.h in same folder and compile again:
c++ -w -std=c++11 -I. -L. -lraylib -lglfw3 -lGL -lopenal -lm -pthread -ldl *.cpp -o test
Please, let me know if it works!
I just tried that a few minutes ago, still got this:
c++ -w -std=c++11 -I"/usr/local/include" -L"/usr/local/lib" -lraylib -lglfw3 -lGL -lopenal -lm -pthread -ldl *.cpp -o Test
/tmp/ccrcvsRQ.o: In function `main':
main.cpp:(.text+0x27): undefined reference to `InitWindow'
main.cpp:(.text+0x31): undefined reference to `SetTargetFPS'
main.cpp:(.text+0x36): undefined reference to `WindowShouldClose'
main.cpp:(.text+0x42): undefined reference to `BeginDrawing'
main.cpp:(.text+0x6f): undefined reference to `ClearBackground'
main.cpp:(.text+0xab): undefined reference to `DrawText'
main.cpp:(.text+0xb0): undefined reference to `EndDrawing'
main.cpp:(.text+0xba): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'all' failed
make: *** [all] Error 1
Hi @BlakeBarnes00,
Have you tried the default examples? Do they work?
Just go to raylib/examples folder and run the make file:
make PLATFORM=PLATFORM_DESKTOP -B
raylib is a C library but it should work perfectly with C++.
Try compiling a single C example (core_basic_window.c) this way:
gcc core_basic_window.c -o test -std=c99 -I. -I../src -L. -L../release/linux -lraylib -lglfw3 -lGL -lopenal -lm -ldl -pthreads
Any news on this issue? Does it work?
I tried it too but I've got the same results. Also it's not recognizes -pthreads command. I'll still trying make ir run.
sorry, my bad, it should be -lpthread. Actually, I saw makefile was also wrong, just updated it.
Ok, full line again:
gcc core_basic_window.c -o core_basic_window -std=c99 -I. -I../src -L. -L../release/linux -lraylib -lglfw3 -lGL -lopenal -lm -lpthread -ldl -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
Have you tried again? Does it work now?
Yes! Thanks! I just sent you an e-mail to tell that it's working, but the makefiles LIBS flags needs update to work.
Just wanted to say that for me it won't work if i put the -lraylib before the source files:
Works:
g++ main.cc -lraylib
Doesn't Work:
g++ -lraylib main.cc
@RGFTheCoder this is expected behaviour with g++ and gcc for that matter, nothing to do with raylib ...
Just wanted to point it out because It took me a really long time to realize and its the issue that the Blake had in his makefile.
@RGFTheCoder have a look at this https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc
To make it work I just sudo ldconfig
hey hello everyone i had the exact same issue as them and i tried all the methods none work any help?
Just wanted to say that for me it won't work if i put the
-lraylibbefore the source files:Works:
g++ main.cc -lraylibDoesn't Work:
g++ -lraylib main.cc
That solved my problem too
Just wanted to say that for me it won't work if i put the
-lraylibbefore the source files:Works:
g++ main.cc -lraylibDoesn't Work:
g++ -lraylib main.cc
Just wanted to say, thank you so much! Everything else was not helping, but this saved me so much headache.