Okay so I have to separate projects one I will call engine
and one I will call game
. My goal is to build the engine project as a dynamic library (I use linux so .so) and then use this in my game project.
This is the structure of projects, the engine project has some libraries that are statically linked. Note I have removed some other vendors and file just to keep this simple as the problem still exists.
include
|----- engine.h
src
|------ engine.c
vendor
|------ glfw (built statically)
|--- build
| |--- src
| |--- libglfw3.a
|--- include
|--- GLFW
|--- ...
I build this with the following cmake(most redacted but important stuff is there) into a build directory and also with another script to add a directory to my build folder with the include/GLFW
and my own headers. Structure is as follows.
set(GLFW_PATH vendor/glfw)
add_library(${PROJECT_NAME} SHARED
include/engine.h
src/engine.c
)
target_include_directories(${PROJECT_NAME} PUBLIC
${GLFW_PATH}/include
)
target_link_libraries(
${PROJECT_NAME}
m
${CMAKE_SOURCE_DIR}/vendor/glfw/build/src/libglfw3.a
OpenGL::GL
)
build
|--- libengine.so
|--- include
|--- engine
| |--- engine.h
|--- GLFW
|--- ...
Everything up until now works fine, using the include_directories in cmake when building the engine and setting it to the glfw/include
in vendor allows me to use <GLFW/glfw3.>
in the engine code and works fine.
Now for the core, I am currently building this with just make but the same issue happens when using cmake. I only have one source file main.c
and this is the structure I both projects together, note I am including the engine header as <engine/engine.h>
.
core
|--- build
| |--- ... (.so is here and include)
|--- CmakeLists.txt
game
|--- main.c
|--- Makefile
This is the make command I am using to use the core dynamic library and all of its header files.
CC = gcc
LIBS = -lengine
LIB_DIR = -L../core/build
INCLUDES = -I../core/build/include
build:
$(CC) main.c $(LIB_DIR) $(INCLUDES) $(LIBS)
When running this command I get the following error (and some more).
/usr/bin/ld: main.c:(.text+0x36): undefined reference to `glfwCreateWindow'
What this is telling me at least is that using #include <enine/engine/h>
in my game's source file worked but once that header tries to use #include <GLFW/glfw3.h>
that is when does not work and any function called from there is now undefined.
Any tips on hot to fix this, thanks.