我尝试使用xcode随附的clang编译attribute((target())) example:
//test.cpp
__attribute__((target("arch=atom")))
void foo() {} // will be called on 'atom' processors.
__attribute__((target("default")))
void foo() {} // will be called on any other processors.
int main ()
{
return 0;
}
clang --version && clang test.cpp
但失败:
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
test.cpp:4:6: error: redefinition of 'foo'
void foo() {} // will be called on any other processors.
^
test.cpp:2:6: note: previous definition is here
void foo() {} // will be called on 'atom' processors.
^
1 error generated.
当我尝试使用clang binary for osx编译此代码时,它会起作用!
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Users/oleksii/Downloads/clang+llvm-8.0.0-x86_64-apple-darwin/bin/.
当我使用在线编译器时,它也可以工作。我尝试了不同的xcode版本,但是它不起作用。为什么行为不同?