在 Qt GUI 应用程序中使用 AsmJit 时出错

Error when using AsmJit within a Qt GUI Application

OS: Windows 10

IDE: Visual Studio 2015

我需要在我的 Qt GUI 应用程序中使用 AsmJit 库 (https://github.com/asmjit/asmjit)。但是在某种程度上是不兼容的。当 QT(QWidget 等)中包含某些 headers 时,事情开始崩溃。

大多数错误源自此行:

ASMJIT_INLINE Error emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, const Operand& o3) {
    return _emit(code, o0, o1, o2, o3);
  }

其中 ASMJIT_INLINE 定义为 __forceinline

当我在VS2015中编译时,出现如下错误:

Severity    Code    Description Project File    Line    Suppression State
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2334   unexpected token(s) preceding '{'; skipping apparent function body  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2238   unexpected token(s) preceding ';'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2062   type 'int' unexpected   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  477 
Error   C2146   syntax error: missing '>' before identifier 'uint64_t'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  248 
Error   C2146   syntax error: missing '>' before identifier 'uint32_t'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  242 
Error   C2146   syntax error: missing '>' before identifier 'uint32_t'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  260 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2143   syntax error: missing ';' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2143   syntax error: missing ',' before '&'    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  494 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  464 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  477 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  479 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2146   syntax error: missing ')' before identifier 'code'  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2061   syntax error: identifier 'uint64_t' Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  284 
Error   C2061   syntax error: identifier 'uint32_t' Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  278 
Error   C2061   syntax error: identifier 'uint32_t' Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  296 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  464 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  479 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2059   syntax error: ')'   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  494 
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  242 
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  248 
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  260 
Error   C3646   'o0': unknown override specifier    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  479 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  464 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  477 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  479 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C3646   'code': unknown override specifier  Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  466 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  477 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  479 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2086   'asmjit::Error asmjit::Assembler::uint32_t': redefinition   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  468 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  470 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  481 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  483 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  485 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  487 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  489 
Error   C2086   'asmjit::Error asmjit::Assembler::Operand': redefinition    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  491 
Error   C2327   'asmjit::Assembler::uint32_t': is not a type name, static, or enumerator    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  494 
Error   C2327   'asmjit::Assembler::uint32_t': is not a type name, static, or enumerator    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  513 
Error   C2433   'asmjit::Assembler::uint32_t': '__forceinline' not permitted on data declarations   Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 
Error   C2433   'asmjit::Assembler::Operand': '__forceinline' not permitted on data declarations    Loader  C:\Users\Ik\Documents\Visual Studio 2015\Projects\DC\loader\CustomBone\contrib\AsmJit\base\assembler.h  472 

考虑到这一点后,我认为 asmjit 不能与 Qt 一起编译的唯一原因是 qt 定义了 emit 宏,它与 asmjit 的 emit 函数冲突。所以扩展宏后的代码:

ASMJIT_INLINE Error emit(uint32_t code,
  const Operand& o0,
  const Operand& o1,
  const Operand& o2,
  const Operand& o3) { return _emit(code, o0, o1, o2, o3); }

变为:

ASMJIT_INLINE Error (uint32_t code,
  const Operand& o0,
  const Operand& o1,
  const Operand& o2,
  const Operand& o3) { return _emit(code, o0, o1, o2, o3); }

Using Qt with 3rd Party Signals and Slots (https://doc.qt.io/qt-5/signalsandslots.html) 提到它:

no_keywords tells Qt not to define the moc keywords signals, slots, and emit, because these names will be used by a 3rd party library, e.g. Boost. Then to continue using Qt signals and slots with the no_keywords flag, simply replace all uses of the Qt moc keywords in your sources with the corresponding Qt macros Q_SIGNALS (or Q_SIGNAL), Q_SLOTS (or Q_SLOT), and Q_EMIT.

no_keywords添加到Qt项目中与将-DQT_NO_KEYWORDS传递给编译器是一样的(基本上将QT_NO_KEYWORDS定义为1)。

这也可以在 asmjit 端修复,但是,asmjit 没有做错任何事。你会遇到与许多其他库相同的问题,如 boost.