【发布时间】:2017-01-05 20:53:01
【问题描述】:
我正在尝试使用 cl.exe(来自 Visual Studio)编译 this c source file。编译失败的具体代码是:
#include <stdio.h>
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx)
{
/* ecx is often an input as well as an output. */
asm volatile("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (*eax), "2" (*ecx));
}
我看到了这个失败:
C:\>cl sgx.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
sgx.c
sgx.c(7): error C2065: 'asm': undeclared identifier
sgx.c(7): error C2143: syntax error: missing ';' before 'volatile'
【问题讨论】:
-
看起来像 gcc 扩展的内联汇编。我不认为VS可以理解它。使用不同的编译器。
-
你试过
__asm而不是asm吗? -
这似乎是 GCC 的扩展内联汇编器,它与 MSVC 不兼容。 MSVC 现在有编译器内在
__cpuid记录在这里:msdn.microsoft.com/en-us/library/hskdteyh.aspx。我会将您的cpuid函数转换为使用内部而不是内联汇编程序。 -
典型的 MSVC 语法是
__asm { .... } -
你的内联汇编是 GCC 兼容的。 MS不同。您必须转换语法和约束。
标签: c visual-studio visual-c++ inline-assembly