尝试与之链接和构建时,动态库中的未定义参考
好的,所以我必须分开一个项目,我将调用引擎
,一个我将调用game
。我的目标是将引擎项目构建为动态库(我使用Linux So .So),然后在我的游戏项目中使用它。
这是项目的结构,引擎项目具有静态链接的一些库。请注意,我已经删除了其他一些供应商,只是为了使此问题保持简单,因为问题仍然存在。
include
|----- engine.h
src
|------ engine.c
vendor
|------ glfw (built statically)
|--- build
| |--- src
| |--- libglfw3.a
|--- include
|--- GLFW
|--- ...
我使用以下cmake(最编辑但最重要的东西存在)构建此构建目录,还使用另一个脚本将目录添加到我的构建文件夹中,并使用include/glfw
和我自己的标头添加。结构如下。
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
|--- ...
到目前为止,一切都可以正常工作,在构建引擎并将其设置为glfw/include
中的cmake中的include_directories允许我使用< glfw/glfw3。> 在发动机代码中,工作正常。
现在,对于核心,我目前正在用“构建”构建此问题,但是使用CMAKE时也会发生同样的问题。我只有一个源文件main.c
,这是我一起项目的结构,请注意,我将引擎标头纳入< engine/Engine.h>
。
core
|--- build
| |--- ... (.so is here and include)
|--- CmakeLists.txt
game
|--- main.c
|--- Makefile
这是我用来使用核心动态库及其所有标头文件的命令。
CC = gcc
LIBS = -lengine
LIB_DIR = -L../core/build
INCLUDES = -I../core/build/include
build:
$(CC) main.c $(LIB_DIR) $(INCLUDES) $(LIBS)
运行此命令时,我会收到以下错误(以及更多)。
/usr/bin/ld: main.c:(.text+0x36): undefined reference to `glfwCreateWindow'
这至少告诉我的是,使用#include< enine/Engine/H>
在我的游戏源文件中有效,但是一旦标头试图使用#include #include< glfw/glfw33 。
关于HOT的任何技巧可以解决此问题,谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论