【问题标题】:Library works with Clang but not with GCC库适用于 Clang,但不适用于 GCC
【发布时间】:2014-01-02 05:17:47
【问题描述】:

为什么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

【问题讨论】:

  • 那不是图书馆;它是一个标题。有区别。标头是源代码;库是目标代码。 (是的,Boost 通过拥有“仅标头库”来混淆事物。)您是将其编译为 C++ 还是 C?它打算编译为 C++ 还是 C?请 — 选择正确的语言,不要使用双重标记。
  • 显示你的编译命令。
  • @JonathanLeffler 许多精心编写的 C 头文件都与 C++ 兼容,这就是 #ifdef __cplusplus 的用途。

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


【解决方案1】:

我怀疑您需要再次在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-26
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-08
    • 2017-11-13
    相关资源
    最近更新 更多