-isystem leads to code wrapped in extern "C"

Bug #1698539 reported by Pedro Kiefer on 2017-06-17
52
This bug affects 9 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Undecided
Unassigned

Bug Description

The toolchain fails to build c++ files correctly when using -isystem, as it treats all headers as being wrapped in `extern "C"`. Other versions of gcc (x86, linaro arm-linux, etc) handles this use case. It seems to be solved on upstreams versions of gcc, but not on this arm-none-eabi version.

I've tested it with 6-2016-q4-major, and 6-2017-q1-update.

related threads:
https://gcc.gnu.org/ml/gcc-patches/2012-06/msg01159.html
https://gcc.gnu.org/ml/gcc-help/2016-02/msg00002.html

description: updated
summary: - -isystem leads to code wrapped in extern C
+ -isystem leads to code wrapped in extern "C"
Tejas Belagod (belagod-tejas) wrote :

Hi Pedro,

What is the symptom you're observing?

Thanks,
Tejas.

One symptom for example is, that the compiler generates errors, when it hits a template declaration: "error: template with C linkage"

Tejas Belagod (belagod-tejas) wrote :

Hi,

I will need a test case to reproduce the issue.

THanks,
Tejas.

Have a file t.cpp:

    #include "t.h"

    int main()
    {}

given t.h is in a subdirectory called test/ and looks like this:

    template < class T >
    void foo();

Compiling t.cpp with:

$ arm-none-eabi-g++ t.cpp -isystem test
In file included from t.cpp:1:0:
test/t.h:2:1: error: template with C linkage
 template < class T >
 ^~~~~~~~

See attached the process output.

Kind regards,

Torsten

Gergely Budai (gbudai76) wrote :

This is a real pain since it makes impossible to include C++ library header files with -isystem. They must be included as standard includes (-I) which makes compilation very noisy.

Gergely Budai (gbudai76) wrote :

The reported behavior is still the same with 7-2017-q4-major. Are there any plans to build the binaries with NO_IMPLICIT_EXTERN_C ?

See: https://gcc.gnu.org/ml/gcc-help/2011-09/msg00157.html

Jim Lloyd (etajim) wrote :

I'm using the g++ 7.2 arm-none-eabi compiler shipped with the Xilinx SDK 2018.1 and am impacted by this issue.

As a workaround, you can include a header and include the needed C++ headers from within an `extern "C++"` block. For example:

extern "C++" {
# include "assert_hash/assert_hash.hpp"
}

Jim Lloyd (etajim) wrote :

@torstenrobitzki I don't think that is a workaround we can use. We have code that extensively uses C++ headers, and we are using CMake plus the [Hunter package management system](https://github.com/ruslo/hunter) to manage our dependencies on external C++ packages such as Boost.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers