I have a C header file (with a .h
extension) and the usual C++ “wrapper” code:
#ifdef __cplusplus
extern "C" {
#endif
/* declarations here */
#ifdef __cplusplus
}
#endif
Now Eclipse CDT (Oxygen) flags everything enclosed in extern "C"
as a syntax error (with the side effect that none of the declarations inside get indexed). The project was upgraded from Eclipse Luna (which had no issues with this), and builds with CMake without any issues.
Other header files have the same extern "C"
construct and are accepted by Eclipse. The problematic file also doesn’t seem to have any unmatched braces.
What’s wrong here, and how can I fix this?
I got a reply to my bug.
The root cause apparently is that I originally generated the Eclipse project files from CMake using
cmake -G "Eclipse CDT4 - Unix Makefiles" ~/src/foobar
This functionality appears to be unmaintained and has caused lots of trouble in the past. Upon their recommendation, I tried installing cmake4eclipse (available on Eclipse Marketplace) and importing the project from scratch.
(If you reuse the same workspace and maintain the project name, even your build configurations are preserved—you may just need to update the paths.)
Moving to cmake4eclipse also eliminates a few other limitations of the previous setup and seems to fix another error with C files dropping out of the index over and over.