我遇到了无法修复的undefined reference to x
个链接器错误。
我不了解发生了什么事,因为我正在与引擎链接,但它似乎无法正常工作。我还尝试将其添加为依赖项,因此也无法解决。有人知道我在做什么错吗?
如果您想窥探所有内容,请访问以下仓库: https://github.com/WinteryFox/VixenEngine
这是我遇到的错误;
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x8a): undefined reference to `graphics::Window::Window(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x19f): undefined reference to `graphics::MasterRender::MasterRender()'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x230): undefined reference to `graphics::MasterRender::addEntity(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, glm::vec<3, float, (glm::qualifier)0>, glm::vec<3, float, (glm::qualifier)0>, float)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x281): undefined reference to `graphics::MasterRender::addPointTemperatureLight(glm::vec<3, float, (glm::qualifier)0> const&, unsigned int, float, float, float)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x28e): undefined reference to `graphics::MasterRender::addTerrain(int, int)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x29e): undefined reference to `graphics::MasterRender::addTerrain(int, int)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2af): undefined reference to `graphics::MasterRender::addTerrain(int, int)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2bf): undefined reference to `graphics::MasterRender::addTerrain(int, int)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2cf): undefined reference to `graphics::MasterRender::render(graphics::Window*, input::Camera*)'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2d7): undefined reference to `graphics::Window::shouldClose() const'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2e3): undefined reference to `graphics::MasterRender::~MasterRender()'
CMakeFiles\test.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x305): undefined reference to `graphics::Window::~Window()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [test\CMakeFiles\test.dir\build.make:94: bin/test.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:1077: test/CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:1089: test/CMakeFiles/test.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:445: test] Error 2
这是我的3个CMakeLists
根CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(VixenEngine)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(SKIP_INSTALL_ALL ON)
option(VIXEN_BUILD_TEST "Build the engine test executable" ON)
#---- BUILD ENGINE ----
add_subdirectory(${CMAKE_SOURCE_DIR}/engine)
#---- BUILD TEST ----
if (VIXEN_BUILD_TEST)
add_subdirectory(${CMAKE_SOURCE_DIR}/test)
endif(VIXEN_BUILD_TEST)
引擎目标CMakeLists.txt
project(engine)
set(CONTRIB "${CMAKE_SOURCE_DIR}/engine/contrib")
# ---- BUILD GLEW ----
set(GLEW "${CONTRIB}/glew")
add_subdirectory("${GLEW}/build/cmake")
# ---- BUILD GLFW ----
set(GLFW "${CONTRIB}/glfw")
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "")
set(GLFW_INSTALL OFF CACHE BOOL "")
set(BUILD_TESTING OFF CACHE BOOL "")
set(BUILD_UTILS OFF CACHE BOOL "")
add_subdirectory("${GLFW}")
# ---- BUILD ZLIB ----
set(ZLIB "${CONTRIB}/zlib")
add_subdirectory("${ZLIB}")
set(ZLIB_INCLUDE_DIR "${ZLIB}" "${CMAKE_BINARY_DIR}/engine/contrib/zlib" CACHE PATH "")
set(ZLIB_LIBRARY zlib CACHE STRING "")
# ---- BUILD LIBPNG ----
set(LIBPNG "${CONTRIB}/libpng")
set(PNG_TESTS OFF CACHE BOOL "")
set(PNG_SHARED ON CACHE BOOL "")
set(PNG_STATIC OFF CACHE BOOL "")
add_subdirectory("${LIBPNG}")
set(PNG_PNG_INCLUDE_DIR "${LIBPNG}" "${CMAKE_BINARY_DIR}/engine/contrib/libpng" CACHE PATH "")
set(PNG_LIBRARY png CACHE STRING "")
# ---- BUILD FREETYPE ----
set(FREETYPE "${CONTRIB}/freetype")
set(FT_WITH_PNG ON CACHE BOOL "")
set(FT_WITH_ZLIB ON CACHE BOOL "")
add_subdirectory("${FREETYPE}")
# ---- BUILD ASSIMP ----
set(ASSIMP "${CONTRIB}/assimp")
set(ASSIMP_BUILD_ASSIMP_TOOLS OFF CACHE BOOL "")
set(ASSIMP_BUILD_SAMPLES OFF CACHE BOOL "")
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "")
set(ASSIMP_NO_EXPORT ON CACHE BOOL "")
set(ASSIMP_BUILD_COLLADA_IMPORTER ON CACHE BOOL "")
set(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF CACHE BOOL "")
add_subdirectory("${ASSIMP}")
# ---- BUILD ENGINE ----
add_library(engine SHARED Window.cpp Window.h Camera.cpp Camera.h shaders/Shader.cpp shaders/Shader.h shaders/Phong.h Mesh.cpp Mesh.h render/EntityRender.cpp render/EntityRender.h Entity.cpp Entity.h Loader.cpp Loader.h Light.cpp Light.h Player.cpp Player.h Model.cpp Model.h Chunk.h Material.h render/EntityRender.cpp render/EntityRender.h Generator.cpp Generator.h render/TerrainRender.cpp render/TerrainRender.h Image.h Texture.h shaders/Phong.cpp shaders/GuiShader.cpp shaders/GuiShader.h font/Font.cpp font/Font.h font/Text.cpp font/Text.h render/FontRender.cpp render/FontRender.h font/Character.h render/MasterRender.cpp render/MasterRender.h shapes/Shapes.h)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
add_dependencies(engine png freetype assimp zlib glfw glew)
target_include_directories(engine PUBLIC ${LIBPNG} ${FREETYPE}/include ${CMAKE_BINARY_DIR}/engine/contrib/assimp/include ${ASSIMP}/include ${LIBPNG} ${GLEW}/include ${CMAKE_SOURCE_DIR}/engine/contrib/glm)
target_link_libraries(engine -static winpthread -dynamic)
target_link_libraries(engine png freetype assimp zlib glfw glew ${OPENGL_LIBRARY})
测试可执行文件CMakeLists.txt
#---- BUILD TEST ----
project(test)
add_executable(test main.cpp)
add_dependencies(test engine)
target_include_directories(test PUBLIC ${CMAKE_SOURCE_DIR}/engine)
target_link_libraries(test engine)
if (WIN32)
target_link_libraries(test gdi32 user32 kernel32)
endif (WIN32)