lundi 22 avril 2019

Compiling C++ library into C program error: expected unqualified-id before string constant extern "C"

I'm working on incorporating some C++ code into my C program and I encountered the following error when I'm trying to add extern "C" to a function definition in a header file foo.h inside a namespace. It seems like the extern "C" is not recognized by the compiler when written inside a namespace? I tested with extern "C" outside namespace and it works. Does anyone have any idea how to get this right?

The error I'm getting: error: expected unqualified-id before string constant extern "C" { ^~~

The code I'm running:

namespace bar {
......
/// Implementation of the run_event_loop(timeout) API function
  #ifdef __cplusplus
extern "C" {
#endif
  void run_event_loop_timeout_st(size_t timeout_ms);
#ifdef __cplusplus
}
#endif
......
}

I'm running gcc version 8.2.0 and command is g++ -g -fPIC -std=c++11 -c ......

Aucun commentaire:

Enregistrer un commentaire