如何编译C++;项目依赖于谷歌';使用g++;(MSYS2/MinGW)? 我在编译我的C++项目时遇到了一个问题,它使用G+(MyS2/2MIW)在Windows上使用。它只是向我吐出了大量的错误信息(见下面的摘录)。我猜它缺少MSVCRT,但我不确定。如果是这样的话,我是否应该告诉g++这个库将在运行时通过msvcrt.dll动态提供,所以它现在不关心引用

如何编译C++;项目依赖于谷歌';使用g++;(MSYS2/MinGW)? 我在编译我的C++项目时遇到了一个问题,它使用G+(MyS2/2MIW)在Windows上使用。它只是向我吐出了大量的错误信息(见下面的摘录)。我猜它缺少MSVCRT,但我不确定。如果是这样的话,我是否应该告诉g++这个库将在运行时通过msvcrt.dll动态提供,所以它现在不关心引用,c++,gcc,mingw,msys2,C++,Gcc,Mingw,Msys2,main.cpp #包括 #包括 #包括 #包括 #包括 int main() {} 编译命令: g++\ -std=c++14-pthread\ main.cpp\ -IE:/库/灯丝/1.8.1/包括\ -IE:/libraries/sdl/2.0.12/x86_64-w64-mingw32/include\ -LE:/libraries/filame/1.8.1/lib/x86_64/mt\ `E:/libraries/sdl/2.0.12/x86_64-w64-mingw32/bin/

main.cpp

#包括
#包括
#包括
#包括
#包括
int main()
{}
编译命令:

g++\
-std=c++14-pthread\
main.cpp\
-IE:/库/灯丝/1.8.1/包括\
-IE:/libraries/sdl/2.0.12/x86_64-w64-mingw32/include\
-LE:/libraries/filame/1.8.1/lib/x86_64/mt\
`E:/libraries/sdl/2.0.12/x86_64-w64-mingw32/bin/sdl2-config--libs`\
-lfilament-LBBACKEND-lbluegl-lbluevk-lfilabridge-lfilaflat-lutils-lgeometry-lsmol-v-libl\
-lpthread
它发出1233KB的消息。以下是一些摘录:

开始时,存在一些太小而无法容纳所有值的错误:

然后是许多模糊的未定义引用:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libraries/filament/1.8.1/lib/x86_64/mt/bluegl.lib(bluegl.dir/Release/BlueGL.obj):(.text$x+0x8): undefined reference to `??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libraries/filament/1.8.1/lib/x86_64/mt/bluegl.lib(bluegl.dir/Release/BlueGL.obj):(.text$x+0x8): undefined reference to `??1_Sentry_base@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libraries/filament/1.8.1/lib/x86_64/mt/bluegl.lib(bluegl.dir/Release/BlueGL.obj):(.text$x+0x8): undefined reference to `??1locale@std@@QEAA@XZ'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libraries/filament/1.8.1/lib/x86_64/mt/bluegl.lib(bluegl.dir/Release/BlueGL.obj):(.text$x+0x8): undefined reference to `??1_Lockit@std@@QEAA@XZ'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/libraries/filament/1.8.1/lib/x86_64/mt/bluegl.lib(bluegl.dir/Release/BlueGL.obj):(.text$x+0x8): undefined reference to `??1?$unique_ptr@V_Facet_base@std@@U?$default_delete@V_Facet_base@std@@@2@@std@@QEAA@XZ'
(many many many more)
其中一些:

undefined reference to `__CxxFrameHandler4'
这让我想到了我的MSVCRT理论

我的g++版本:

$ g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Windows的二进制灯丝附带不同的lib版本:mt、md、mtd和mdd。我认为mt版本意味着没有到MSVCRT的静态链接,因此在编译过程中没有引用问题。也许我在这里误解了一些事情?

我看了一下灯丝,并尝试使用MSYS2和MinGW-w64构建它,但它无法在开箱即用的情况下运行。对于初学者来说,
CMakeLists.txt
充满了
if(WIN32)
应该在哪里
if(MSVC)
。不管是谁写的,都假设Windows构建总是用MSVC完成的。因此,这个项目需要一些工作,然后才能与明威建设。感谢您的投资和分享。但是你认为有必要用gcc来建造灯丝吗?难道我不能使用已经编译好的
.lib
文件与gcc进行静态链接吗?根据我的经验,混合使用不同编译器(甚至同一编译器的不同版本)构建的库常常会出现问题。这通常意味着不同的标准C/C++库。例如,在一个库中使用
malloc()
分配的内存,在另一个库中使用
free()
释放的内存,如果这些函数不是来自同一个标准库,可能会导致应用程序崩溃。如果你非常小心地避免这些问题,你可能会逃脱混合编译器,但很容易犯错误。。。
undefined reference to `__CxxFrameHandler4'
$ g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.