图书馆与Clang合作但不与GCC合作

时间:2014-01-02 05:17:47

标签: c++ c gcc g++ clang

为什么this library与Apple LLVM 5.0(clang-500.2.79)完美配合,而仅包含头文件会导致GCC 4.9错误?

产生错误的最小源文件:

#include <divsufsort.h>

int main() {  
  return 0;
}

我在GCC 4.9中遇到的错误:

In file included from main.cpp:1:0:
/usr/local/include/divsufsort.h:74:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:86:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:94:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:108:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:123:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:137:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:152:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API
 ^
/usr/local/include/divsufsort.h:169:1: error: expected constructor, destructor, or type conversion before '(' token
 DIVSUFSORT_API

1 个答案:

答案 0 :(得分:2)

我怀疑你需要再次在libdivsufsort目录上运行./configure,并为你想要使用的编译器预先设置CC环境变量。 (CC为“c”代码.CXX为c ++代码)。然后重建。

cd ~/libdivsufsort-2.0.1
make clean
CC=gcc
CXX=g++
./configure
make

试试此链接:Configuring for a compiler different than the default while running configure