0

Why does this library work perfectly with Apple LLVM 5.0 (clang-500.2.79), while merely including the header file causes an error with GCC 4.9?

Minimal source file that produces the error:

#include <divsufsort.h>

int main() {  
  return 0;
}

The error I get with 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
zoo
  • 1,901
  • 1
  • 17
  • 25
  • 2
    That's not a library; it is a header. There's a difference. A header is source code; a library is object code. (Yes, Boost confuses things by having 'header-only libraries'.) Are you compiling it as C++ or as C? Is it intended to be compiled as C++ or as C? Please — choose the correct language and do not dual tag. – Jonathan Leffler Jan 02 '14 at 05:27
  • 2
    Show your compilation commands. – Lightness Races in Orbit Jan 02 '14 at 05:33
  • @JonathanLeffler Many well-eritten C headers are C++-compatible, that's what `#ifdef __cplusplus` is for. – n. m. could be an AI Jan 02 '14 at 06:41

1 Answers1

2

I suspect that you need to run ./configure on the libdivsufsort directory again with the CC environment variable pre-set for the compiler you intend to use. (CC for "c" code. CXX for c++ code). Then rebuild.

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

Try this link: Configuring for a compiler different than the default while running configure

Community
  • 1
  • 1
selbie
  • 100,020
  • 15
  • 103
  • 173