Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使无法链接它刚刚编译的内容_C++_Cmake_Mingw_Ld - Fatal编程技术网

C++ 使无法链接它刚刚编译的内容

C++ 使无法链接它刚刚编译的内容,c++,cmake,mingw,ld,C++,Cmake,Mingw,Ld,我在一个相当小的爱好项目中,我们正在创建一个游戏,或者至少正在尝试这样做。。。我们面临的主要问题是,我们能够在MacOS和Linux上编译该项目,但不能在Windows上编译 我们使用GLFW作为OpenGL的接口,所以我们需要在屏幕上看到任何东西。问题是,当我们告诉Make做它的事情时,它编译每个单独的模块,但由于未定义引用而无法链接它们。虽然这可能有道理,但奇怪的是,这些未知引用都有前缀\uuuu imp\uuu,这在源代码中并不存在。示例:我们使用了方法glfwInit,但在尝试创建项目时

我在一个相当小的爱好项目中,我们正在创建一个游戏,或者至少正在尝试这样做。。。我们面临的主要问题是,我们能够在MacOS和Linux上编译该项目,但不能在Windows上编译

我们使用GLFW作为OpenGL的接口,所以我们需要在屏幕上看到任何东西。问题是,当我们告诉Make做它的事情时,它编译每个单独的模块,但由于未定义引用而无法链接它们。虽然这可能有道理,但奇怪的是,这些未知引用都有前缀
\uuuu imp\uuu
,这在源代码中并不存在。示例:我们使用了方法
glfwInit
,但在尝试创建项目时,我们得到:
graphicsengine/libgraphicsengine.a(graphics.cpp.obj):graphics.cpp:(.text+0xa):未定义的对“\u imp\u glfwInit”的引用

做了一些研究后,我找到了答案。它失败了,因为编译后那里唯一的库是
libglfw3.a
,没有任何类型的dll或dll提示。相应地重命名此文件没有帮助,放置预编译的二进制文件也没有帮助。删除此文件会导致它重新编译和重新出现,因此请清楚地知道它在哪里

我们还尝试切换到clang,因为它可能有一个更智能的链接器,但它一开始不想编译任何东西

我在这方面做了很多研究,发现了无数答案和论坛帖子,上面都有相似甚至相同的问题,每个人都有不同的解决方案,没有一个对我们有用

为了生成Makefile,我们在主子目录中使用CMake和以下脚本(不用担心,它是从上面调用的,到目前为止我们已经完成了这项工作):

其余重要的cmake调用位于父目录中

以下是自定义生成脚本调用的cmake/make的完整日志:

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>
如果您想知道,这是我们的项目结构:

上面的CMakeLists.txt就是您在/source中看到的

其余的模块都是以同样的方式构建的,除了glfw,这是一个你可以在他们的网站上找到的模块

在这个时候,我们或多或少地对寻找解决方案感到无助和厌倦,在这个时候,我们只是尝试一些东西,直到它起作用,但最终却把本来不应该存在的一切都搞得一团糟,我们都知道这是如何结束的。。。(咳嗽)这些分支中的哪一个是我做的事情使它做了另一件事?(咳嗽)我们希望你们中的一些人(如此)可能比我们中的任何人有更好的方法来找到解决方案。请随意询问任何其他可能帮助您找到工作的问题

提前谢谢


以:sDev的名义,我们找到了它

问题实际上出在我们的
图形中。hpp

我们有一行
#define GLFW_DLL

这是错误的,因为它必须

#定义GLFW#u STATIC


现在它工作了

我们找到了

问题实际上出在我们的
图形中。hpp

我们有一行
#define GLFW_DLL

这是错误的,因为它必须

#定义GLFW#u STATIC


现在它在您的
CMakeLists.txt
中起作用,您有
add_子目录(graphicsengine)
,然后
add_子目录(glfw-3.2.1)
。但构建顺序相反:
构建目标glfw
,然后
构建目标图形引擎
。怎么可能呢?当处理
graphicsengine
文件夹时,
graphicsengine
无法访问
glfw
目标时,如何将
graphicsengine
链接到
glfw
然后才是后面的
目标链接库(${PROJECT\u NAME}glfw)
实际上,我的第二个问题更重要:在
graphicsengine
下构建库,它使用
glfw
。但是
glfw
库在后面会提到,这意味着您甚至没有为
graphicsengine
提供
glfw
头。它看起来像是
graphicsengine
使用自己的glfw作为标题和链接。“它自己的glfw”与您的glfw不兼容。@Tsyvarev我尝试将调用移动到
target\u link\u库(…glfw)
,在调用链接其他所有内容之前,唯一更改的是生成顺序。从链接CXX可执行文件\u PR0.exe开始,其余的错误仍然存在。只需交换
添加子目录的顺序,什么也不改变:如果
图形引擎
没有链接到
glfw
目标,则在交换顺序后它不会链接到该目标。
graphicsengine
CMakeList.txt
有问题,但您没有显示它。在
CMakeLists.txt
中,您有
add_子目录(graphicsengine)
,然后
add_子目录(glfw-3.2.1)
。但构建顺序相反:
构建目标glfw
,然后
构建目标图形引擎
。怎么可能呢?当处理
graphicsengine
文件夹时,
graphicsengine
无法访问
glfw
目标时,如何将
graphicsengine
链接到
glfw
然后才是后面的
目标链接库(${PROJECT\u NAME}glfw)
实际上,我的第二个问题更重要:在
graphicsengine
下构建库,它使用
glfw
。但是
glfw
库在后面会提到,这意味着您甚至不提供
glfw
头文件
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>