Skip to content

Linking C++ #14466

@sqrtroot

Description

@sqrtroot

Description

When linking the usage of c++ is not always detected correctly, and thus the wrong linker is used resulting in linker errors.

Steps to reproduce the issue

Folder structure like this:

├── main.c
├── Makefile
└── src
    ├── blink.cpp
    └── Makefile

Here's the contents of the files:
example.tar.gz
(If you want to try this you'll have to set the correct path for RIOT)

Expected results

Either g++ is used as a linker (which is down when there is an cpp file in the main application) or libstdc++ is also included in the link process when ld is used.

Actual results

gcc is used as a linker which doesn't link against libstdc++. Just adding a single empty file ending in .cpp makes RIOT use g++ as a linker

Versions


Operating System Environment
----------------------------
         Operating System: "Arch Linux" 
                   Kernel: Linux 5.7.7-arch1-1 x86_64 unknown
             System shell: GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
             make's shell: GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)

Installed compiler toolchains
-----------------------------
               native gcc: gcc (GCC) 10.1.0
        arm-none-eabi-gcc: arm-none-eabi-gcc (Arch Repository) 10.1.0
                  avr-gcc: missing
         mips-mti-elf-gcc: missing
               msp430-gcc: missing
     riscv-none-embed-gcc: missing
     xtensa-esp32-elf-gcc: missing
   xtensa-esp8266-elf-gcc: missing
                    clang: clang version 10.0.0 

Installed compiler libs
-----------------------
     arm-none-eabi-newlib: "3.3.0"
      mips-mti-elf-newlib: missing
  riscv-none-embed-newlib: missing
  xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
                 avr-libc: missing (missing)

Installed development tools
---------------------------
                   ccache: ccache version 3.7.9
                    cmake: cmake version 3.17.3
                 cppcheck: Cppcheck 2.1
                  doxygen: missing
                      git: git version 2.27.0
                     make: GNU Make 4.3
                  openocd: Open On-Chip Debugger 0.10.0
                   python: Python 3.8.3
                  python2: Python 2.7.18
                  python3: Python 3.8.3
                   flake8: error: /sbin/python3: No module named flake8
               coccinelle: missing

Metadata

Metadata

Labels

Area: C++Area: C++ wrapperType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions