1、llvm-mingw与ming-w64区别
llvm编译出来的产物可能直接依赖Windows的API集,但ming-w64编译出来的程序直接依赖系统库,系统库可能再依赖API集。
与msvc编译的差异
- 使用msvc编译里添加的许多库在使用mingw时不需要再添加声明了。
- 使用mingw的使用的win32库名与原库名稍有变化,在msvc中添加的是xxx.lib,在mingw是添加的是libxxx.a
编译相关问题
1、未正确使用相关标记。
添加-frtti即可
../third_party/icu/icu4c/source/i18n/unum.cpp:640:31: error: use of dynamic_cast requires -frtti
const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
2、MinGW不支持Windows异常处理__try
../third_party/flutter/engine/flutter/fml/thread.cc:84:3: error: use of undeclared identifier '__try'
__try {
^
1 error generated
3、数据类型转换问题
在mac、ubuntu上编译只有几处报错,而使用MinGW编译时全部报错,而且是针对模板类型的构造函数。如果给构造函数赋值一个double的常量也可以正常编译,但如果是变量就会报错,使用(float)强转的话也可以正常编译;直接将一个double赋值给一个float变量也没有问题。
解决方法:添加-Wno-c++11-narrowing
../foundation/arkui/ace_engine/frameworks/core/components_ng/layout/box_layout_algorithm.cpp:43:17: error: non-constant-expression cannot be narrowed from type 'double' to 'float' in initializer list [-Wc++11-narrowing]
layoutConstraint.maxSize.Height() - safeArea.topRect_.Height() - safeArea.bottomRect_.Height() };
4、constexpr变量的值需要在编译时就要确定,对于构造函数也需要使用constexpr进行修饰才行。
constexpr explicit Color(uint32_t value) : colorValue_(ColorParam { .value = value }) {}
../foundation/arkui/ace_engine/frameworks/core/components_ng/pattern/scroll/inner/scroll_bar.h:38:17: error: constexpr variable 'PRESSED_BLEND_COLOR' must be initialized by a constant expression
constexpr Color PRESSED_BLEND_COLOR = Color(0x19000000);
^ ~~~~~~~~~~~~~~~~~
5、自定义的enum、变量名与系统gdi头文件中定义的宏冲突。
添加NOGDI宏定义解决。
defines = [ “NOGDI” ]
../third_party/one/one.h:29:5: error: expected identifier
ALTERNATE,
^
C:/Users/client/Downloads/llvm-mingw-20230614-msvcrt-x86_64/include/wingdi.h:100:19: note: expanded from macro 'ALTERNATE'
#define ALTERNATE 1
6、暂不清楚是什么问题,直接注释掉了。
../foundation/arkui/ace_engine/frameworks/core/components/common/layout/grid_system_manager.cpp:121:31: error: cannot pass non-trivial object of type 'RefPtr<GridContainerInfo>' to variadic function; expected type from format string was 'void *' [-Wnon-pod-varargs]
LOGD("parent addr:%p",parent);
~~ ^~~~~~
../foundation/arkui/ace_engine/frameworks/base/log/log_wrapper.h:43:48: note: expanded from macro 'LOGD'
#define LOGD(fmt, ...) PRINT_LOG(DEBUG, fmt, ##__VA_ARGS__)
~~~ ^~~~~~~~~~~
../foundation/arkui/ace_engine/frameworks/base/log/log_wrapper.h:39:19: note: expanded from macro 'PRINT_LOG'
##__VA_ARGS__); \
^~~~~~~~~~~
7、未定义的符号
使用动态库引用静态库,而静态库使用的是dllexport函数导出,动态库使用visibility(“default”)导出,导出动态库中所有函数均不能正常导出。
llvm-mingw-20230614-msvcrt-x86_64\bin/clang++ -target x86_64-pc-windows-gnu -rtlib=compiler-rt -stdlib=libc++ -lunwind -lpthread -Qunused-arguments -fuse-ld=lld -o ./test.exe @./test.exe.rsp
ld.lld: error: undefined symbol: Two::toString()
8、win32已有的函数,在项目中重新定义
根据警告信息重新声明需要添加dllimport,使用dllimport标记后,出现警告信息2:重新声明方法不能使用dllimport。这个提示前后矛盾。后尝试一个函数定义多次是可以的,但不能有多个实现。
暂未找到好的解决方案
警告提示1
In file included from ../foundation/arkui/napi/native_engine/impl/quickjs/quickjs_native_engine.cpp:38:
../third_party/bounds_checking_function/include/securec.h:527:21: warning: 'wscanf_s' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
SECUREC_API int wscanf_s(const wchar_t *format, ...);
^
C:/Users/client/Downloads/llvm-mingw-20230614-msvcrt-x86_64/include/sec_api/wchar_s.h:278:23: note: previous declaration is here
_CRTIMP int __cdecl wscanf_s(const wchar_t *_Format, ...);
警告提示2
In file included from ../foundation/arkui/napi/native_engine/native_safe_async_work.cpp:22:
../commonlibrary/c_utils/base/include/securec.h:106:9: warning: -------dllimport-------- [-W#pragma-messages]
#pragma message("-------dllimport--------")
^
../commonlibrary/c_utils/base/include/securec.h:244:21: warning: redeclaration of 'swprintf_s' should not add 'dllimport' attribute [-Wdll-attribute-on-redeclaration]
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
^
C:/Users/client/Downloads/llvm-mingw-20230614-msvcrt-x86_64/include/sec_api/wchar_s.h:256:15: note: previous declaration is here
int __cdecl swprintf_s(wchar_t *_Dst,size_t _SizeInWords,const wchar_t *_Format,...);
9、mingw头文件与win10头文件关于此方法声明不一致
暂未找到好的解决方案
STDMETHOD(GetGlyphImageFormats)(
UINT16 glyphId,
UINT32 pixelsPerEmFirst,
UINT32 pixelsPerEmLast,
_Out_ DWRITE_GLYPH_IMAGE_FORMATS* glyphImageFormats
) PURE;
virtual DWRITE_GLYPH_IMAGE_FORMATS STDMETHODCALLTYPE GetGlyphImageFormats() = 0;
../third_party/flutter/skia/src/ports/SkScalerContext_win_dw.cpp:505:47: error: too many arguments to function call, expected 0, have 4
auto rs = fontFace4->GetGlyphImageFormats(glyph.getGlyphID(), 0, UINT32_MAX, &f);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/client/Downloads/llvm-mingw-20230614-msvcrt-x86_64/include/dwrite_3.h:8577:58: note: 'GetGlyphImageFormats' declared here
virtual DWRITE_GLYPH_IMAGE_FORMATS STDMETHODCALLTYPE GetGlyphImageFormats(
10、 undefined symbol: __declspec(dllimport) bind
添加ws2_32库即可
libs = [ “ws2_32” ]
ld.lld: error: undefined symbol: __declspec(dllimport) bind
>>> referenced by obj/third_party/openssl/crypto/bio/crypto_source/b_sock2.o:(BIO_bind)