2017-05-29 36 views
1

我在一個相當小愛好的項目,我們正在創造一個遊戲,或者至少試圖這樣做......我們所面臨的主要問題是,我們能在MacOS和Linux上編譯項目,但不能在Windows上編譯。讓無法鏈接的東西,它確實只是編譯

我們正在使用GLFW作爲OpenGL的一個接口,所以讓我們獲得任何東西在屏幕上可見它是必需的。問題是,當我們告訴Make做它的事情時,它會編譯每個單獨的模塊,但由於未定義的引用而無法鏈接它們。雖然這可能是有道理的奇怪的是,這些未知的引用都有前綴__imp_,這是不存在的來源。示例:我們使用方法glfwInit,但試圖進行該項目時,我們得到:graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0xa): undefined reference to `_imp__glfwInit'

做了一些研究後,我發現This SO Question其中我試過了答案。它失敗了,因爲編譯後的唯一lib是libglfw3.a,在dll上沒有任何類型的dll或提示。相應地重命名這個文件沒有幫助,放置預編譯的二進制文件也沒有幫助。刪除這個文件導致它重新編譯並重新出現,所以清楚地知道它在哪裏。

我們也嘗試切換到鐺因爲也許它有一個更智能的連接,但它並沒有要編譯擺在首位什麼。

我進行了大量的研究這一點,我發現無數的SO答案和人類似甚至相同的問題論壇主題,每一個都有不同的解決方案,他們沒有爲我們工作。

要生成我們使用CMake的與主子目​​錄下面的腳本生成文件(不用擔心,它就會從上面傳來叫,我們得到了迄今爲​​止工作):

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) 
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) 
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) 

add_subdirectory(graphicsengine) 
add_subdirectory(fileSys) 
add_subdirectory(networking) 
add_subdirectory(game) 

add_subdirectory(glfw-3.2.1) 
include_directories(glfw-3.2.1/include) 

if (UNIX AND NOT APPLE) 
    find_package(OpenGL REQUIRED) 
    include_directories(${OPENGL_INCLUDE_DIR}) 
endif() 

add_executable(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp") 

target_link_libraries(${PROJECT_NAME} graphicsengine fileSys networking game) 

if (APPLE) 
    target_link_libraries(${PROJECT_NAME} "-framework OpenGL") 
endif() 
if (WIN32) 
    target_link_libraries(${PROJECT_NAME} opengl32 gdi32) 
endif() 
if (UNIX AND NOT APPLE) 
    target_link_libraries(${PROJECT_NAME} ${OPENGL_gl_LIBRARY}) 
endif() 

target_link_libraries(${PROJECT_NAME} glfw) 

install(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_DIR}) 

其餘重要cmake的通話是在父目錄

這裏的cmake是一個完整的日誌/做出一個自定義生成腳本調用:

debug 
release 
-- The CXX compiler identification is GNU 5.3.0 
-- Check for working CXX compiler: D:/MinGW/bin/g++.exe 
-- Check for working CXX compiler: D:/MinGW/bin/g++.exe -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Detecting CXX compile features 
-- Detecting CXX compile features - done 
-- The C compiler identification is GNU 5.3.0 
-- Check for working C compiler: D:/MinGW/bin/gcc.exe 
-- Check for working C compiler: D:/MinGW/bin/gcc.exe -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Looking for pthread.h 
-- Looking for pthread.h - found 
-- Looking for pthread_create 
-- Looking for pthread_create - not found 
-- Looking for pthread_create in pthreads 
-- Looking for pthread_create in pthreads - not found 
-- Looking for pthread_create in pthread 
-- Looking for pthread_create in pthread - found 
-- Found Threads: TRUE 
-- Could NOT find Vulkan (missing: VULKAN_INCLUDE_DIR) 
-- Looking for dinput.h 
-- Looking for dinput.h - not found 
-- Looking for xinput.h 
-- Looking for xinput.h - not found 
-- Performing Test _GLFW_HAS_DEP 
-- Performing Test _GLFW_HAS_DEP - Success 
-- Performing Test _GLFW_HAS_ASLR 
-- Performing Test _GLFW_HAS_ASLR - Success 
-- Performing Test _GLFW_HAS_64ASLR 
-- Performing Test _GLFW_HAS_64ASLR - Failed 
-- Using Win32 for window creation 
-- Configuring done 
-- Generating done 
-- Build files have been written to: D:/cpp-neon/Workspace/Supermerged 
--------------MAKE STARTS HERE-------------- 
[ 60%] Built target glfw 
[ 68%] Built target graphicsengine 
[ 76%] Built target fileSys 
[ 84%] Built target networking 
[ 92%] Built target game 
[ 96%] Linking CXX executable Submerged_PR0.exe 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0xa): undefined reference to `_imp__glfwInit' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x45): undefined reference to `_imp__glfwCreateWindow' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x55): undefined reference to `_imp__glfwTerminate' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x64): undefined reference to `_imp__glfwMakeContextCurrent' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x71): undefined reference to `_imp__glfwWindowShouldClose' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x98): undefined reference to `_imp__glfwSwapBuffers' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0x9f): undefined reference to `_imp__glfwPollEvents' 
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0xa8): undefined reference to `_imp__glfwTerminate' 
collect2.exe: error: ld returned 1 exit status 
source\CMakeFiles\Submerged_PR0.dir\build.make:101: recipe for target 'source/Submerged_PR0.exe' failed 
mingw32-make[2]: *** [source/Submerged_PR0.exe] Error 1 
CMakeFiles\Makefile2:102: recipe for target 'source/CMakeFiles/Submerged_PR0.dir/all' failed 
mingw32-make[1]: *** [source/CMakeFiles/Submerged_PR0.dir/all] Error 2 
Makefile:128: recipe for target 'all' failed 
mingw32-make: *** [all] Error 2 
Make Failed, Aborting Install 
PS D:\cpp-neon\Workspace\Supermerged> 

如果你想知道,T他是我們的項目結構:

以上的CMakeLists.txt是你/源

模塊的其餘部分是建立在以同樣的方式,除了GLFW,這是看到了一個可以在他們的網站上找到的那個

在這個時候,我們或多或少無助地厭倦了尋找解決方案,我們只是嘗試東西,直到它發揮作用,但結果是一個巨大的混亂我們都知道如何結束...... (c ough)這些分支是一個在那裏我做了,使得它做其他的事情,我們希望你們中的一些(SO)可能必須找到比我們的解決方案更好的辦法嘛?(咳嗽)。隨意問任何可能會幫助你找到有效的東西!

在此先感謝!

在名稱:發展局局長

+1

在你的'CMakeLists.txt'中,你有'add_subdirectory(graphicsengine)',那麼'add_subdirectory(GLFW-3.2.1)'。但是構建順序是**反轉**:'構建目標glfw',然後'構建目標graphicsengine'。這怎麼可能?你怎麼把'graphicsengine'和'glfw'聯繫起來,因爲在你處理'graphicsengine'文件夾時'glfw'目標是**不可訪問的**? – Tsyvarev

+0

@Tsyvarev的確很奇怪,但我認爲構建順序實際上取決於'target_link_libraries($ {PROJECT_NAME} graphicsengine fileSys網絡遊戲)'這一行,然後纔在'target_link_libraries($ {PROJECT_NAME} glfw)' –

+0

這一行開始。 ,我的第二個問題更重要:在'graphicsengine'下建立庫,**使用**'glfw'。但'glfw'庫在**後期被註明,這意味着你甚至不會爲'graphicsengine'提供'glfw'頭文件。它看起來像'graphicsengine'使用**自己的glfw **標題和鏈接。和「它自己的glfw」與你的不兼容。 – Tsyvarev

回答

0

我們找到了!

這個問題實際上是我們graphics.hpp

我們有行#define GLFW_DLL

這是錯誤的,因爲它必須

#define GLFW_STATIC

而現在它的工作原理