raylib: [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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (7 by maintainers)
Just wanted to say that for me it won’t work if i put the
-lraylib
before the source files:Works:
Doesn’t Work:
sorry, my bad, it should be
-lpthread
. Actually, I saw makefile was also wrong, just updated it.Ok, full line again:
To make it work I just
sudo ldconfig
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:
Please, let me know if it works!