'asm'中不一致的操作数约束

Inconsistent operand constraints in an 'asm'

本文关键字:操作数 约束 asm 不一致      更新时间:2023-10-16

我正在使用Qt,并希望包含ttmath库。它在Windows XP和Windows 7上测试良好。我现在在 Ubuntu 上使用 Qt-creator,当我尝试编译项目时,它给了我以下错误:

.../ttmathuint_x86.h:637: error: inconsistent operand constraints in an 'asm'
 : "cc", "memory" );
                   ^

部分代码如下所示:

#ifdef __GNUC__
uint dummy, dummy2;
__asm__  __volatile__(
        "xorl %%edx, %%edx    n"
        "negl %%eax           n"  // CF=1 if rax!=0 , CF=0 if rax==0
    "1:                                 n"
        "movl (%%esi,%%edx,4), %%eax    n"
        "sbbl %%eax, (%%ebx,%%edx,4)    n"
        "incl %%edx                     n"
        "decl %%ecx                     n"
        "jnz 1b                         n"
        "adc %%ecx, %%ecx               n"
    : "=c" (c), "=a" (dummy), "=d" (dummy2)
    : "0" (b),  "1" (c), "b" (p1), "S" (p2)
    : "cc", "memory" );
#endif

该错误仅在我将解析器添加到我的项目时显示,例如上一个示例中的解析器,如下所示:http://www.ttmath.org/samples

我不知道为什么这不起作用,因为我对汇编或编译过程知之甚少。

我在互联网上读到解决方案是在我的".pro"文件中添加QMAKE_CXXFALGS = -fno-gcse,但它不起作用。

此错误的原因是 -fPIC-fpic 编译器标志,该标志指示应发出与位置无关的代码。为了定位变量,它使用全局偏移表,其指针存储在 ebx 中。因此,使用此标志,不允许在内联程序集中使用ebx

根据 https://software.intel.com/en-us/blogs/2014/12/26/new-optimizations-for-x86-in-upcoming-gcc-50-32bit-pic-mode,这在GCC 5.0中发生了变化。该库可能会更改您的标志,因此您必须查看是否可以更改代码。

就我而言,我可以解决它将我的 gcc 更新到 5.0 版

这是源链接 https://askubuntu.com/questions/618474/how-to-install-the-latest-gcurrently-5-1-in-ubuntucurrently-14-04,这些是他们建议的命令(以及我使用的命令):

sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get 更新sudo apt-get install gcc-5 g++-5

sudo update-alternatives

--install/usr/bin/gcc gcc/usr/bin/gcc-5 60 --slave/usr/bin/g++ g++/usr/bin/g++-5