c++ - 如何使用 g++ (MSYS2/MinGW) 在 Windows 上根据 Google 的灯丝库编译 C++ 项目?
问题描述
我对在尝试编译我的 C++ 项目时遇到的问题有点一头雾水,该项目使用Google 的 Filament 库,在 Windows 上使用g++ (MSYS2/MinGW)。它只是向我吐出大量错误消息(见下面的摘录)。我的猜测是它缺少 MSVCRT,但我不确定。如果是这种情况,我是否应该能够告诉 g++ 这个库将在运行时通过动态提供,msvcrt.dll
所以它现在不关心引用?
main.cpp
#include <filament/Engine.h>
#include <filament/SwapChain.h>
#include <filament/Renderer.h>
#include <filament/View.h>
#include <utils/EntityManager.h>
int main()
{}
编译命令:
g++ \
-std=c++14 -pthread \
main.cpp \
-IE:/libraries/filament/1.8.1/include \
-IE:/libraries/sdl/2.0.12/x86_64-w64-mingw32/include \
-LE:/libraries/filament/1.8.1/lib/x86_64/mt \
`E:/libraries/sdl/2.0.12/x86_64-w64-mingw32/bin/sdl2-config --libs` \
-lfilament -lbackend -lbluegl -lbluevk -lfilabridge -lfilaflat -lutils -lgeometry -lsmol-v -libl \
-lpthread
它吐出 1233 KB 的消息。以下是一些摘录:
一开始有一些is-too-small-to-hold-all-values -errors:
In file included from E:/libraries/filament/1.8.1/include/backend/Platform.h:22,
from E:/libraries/filament/1.8.1/include/filament/Engine.h:20,
from main.cpp:2:
E:/libraries/filament/1.8.1/include/backend/DriverEnums.h:631:30: warning: 'filament::backend::SamplerParams::<unnamed union>::<unnamed struct>::filterMag' is too small to hold all values of 'enum class filament::backend::SamplerMagFilter'
631 | SamplerMagFilter filterMag : 1; //!< magnification filter (NEAREST)
| ^~~~~~~~~
E:/libraries/filament/1.8.1/include/backend/DriverEnums.h:632:30: warning: 'filament::backend::SamplerParams::<unnamed union>::<unnamed struct>::filterMin' is too small to hold all values of 'enum class filament::backend::SamplerMinFilter'
632 | SamplerMinFilter filterMin : 3; //!< minification filter (NEAREST)
| ^~~~~~~~~
(some more cut out)
接下来是 40 行告诉我:
Warning: corrupt .drectve at end of def file
然后是很多神秘的未定义引用:
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 的 Binary Filament 附带不同的 lib 版本:mt、md、mtd 和 mdd,在 Microsoft 网站上进行了说明。我认为 mt 版本意味着没有到 MSVCRT 的静态链接,因此在编译期间没有参考问题。也许我在这里误解了一些事情?
解决方案
推荐阅读
- ios - 自定义 NavigationView 顶栏
- docker - 通过 dockerfile 更新 matomo 自定义变量
- javascript - 如何向需要密码的 api 发出 http 请求,而无需在我的 javascript 代码中写入密码?
- python - SymPy 可以简化包含具有复数基数的指数的实数表达式吗?
- c# - MassTransit 自动添加消费者
- groovy - 我如何从 Groovy 脚本运行 Oracle 函数并获取结果,返回 RECORD 类型的值
- javascript - 多个本地文件上传 React + Node JS 不起作用
- javascript - Datapicker 检查用户的年龄,有时会在 DB 中保存错误的值
- java - Java使用正则表达式获取字符串中最后一个方括号之间的文本
- php - WordPress:图像宽度不得超过 50px 错误