带有 Mountain Lion 的 g++ 是否支持 -msse4.2

Does g++ with Mountain Lion supports -msse4.2?

本文关键字:支持 -msse4 是否 g++ Mountain Lion 带有      更新时间:2023-10-16

我正在尝试运行一个使用该函数的程序__builtin_popcountll。当我使用 makefile 编译代码时,它使用命令/标志编译源文件,如下所示:

g++ -c -Wall `pkg-config opencv --cflags` -I./include -O3 -fopenmp -msse4.2 src/Utils.cpp -o src/Utils.o

它在没有任何错误/警告的情况下编译。但是,当我尝试链接对象 (.o( 文件以构建可执行文件时,出现undefined symbols错误。

这是命令:

g++ src/BoostDesc.o src/Utils.o src/main.o `pkg-config opencv --libs` -lgomp -o main

这是完整的错误:

Undefined symbols for architecture x86_64:
  "___builtin_popcountll", referenced from:
      __ZN9boostDesc5Utils12matchHammingERKN2cv3MatERKSt6vectorIS2_SaIS2_EERS5_IS5_INS1_6DMatchESaISA_EESaISC_EE.omp_fn.0 in Utils.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [main] Error 1

我在Apple的网站上查找了gcc的手册页,它表明该标志有效,我假设它也应该适用于g ++。有人可以确认或反驳使用此内置函数的可能性吗?哗啦!

g++ --version返回以下内容:

i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

此优化是通过执行以下操作来指定的: -mpopcnt-march=corei7到编译中。

取一个样本:

% cat popcountl.c 
int main(int argc , char** argv)
{
  volatile long long x = 0xf0f0f0f0f0f0f0f0;
  return  __builtin_popcountll(x);
}

事实证明,该版本的 g++ 不支持:

~/D/e/popcountl [1]> /Applications/Xcode 4.6.3.app/Contents/Developer/usr/bin/g++ -mpopcnt -c popcountl.c
cc1plus: error: unrecognized command line option "-mpopcnt"
~/D/e/popcountl [1]> /Applications/Xcode 4.6.3.app/Contents/Developer/usr/bin/g++ -march=corei7 -c popcountl.c
popcountl.c:1: error: bad value (corei7) for -march= switch
popcountl.c:1: error: bad value (corei7) for -mtune= switch
~/D/e/popcountl> /Applications/Xcode 4.6.3.app/Contents/Developer/usr/bin/g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

不过适用于Xcode5 g ++。

% g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
g++ -mpopcnt -c popcountl.cpp 
dhcp-3-127:~% otool -tV popcountl.o                                                         
popcountl.o:
:
0000000000000024    popcntq %rax, %rax

看起来此优化的标志在 XCode 提供的编译器的 4.6 版本中不存在,但在 XCode 编译器的 5.0 版本中存在。

请记住,您实际上是在运行带有 g++ 前端的 llvm 编译器,因此它实际上并没有运行官方的 g++;这可能是它在这种情况下无法正常工作的根本原因。