Can't compile/link simple c++ program with kendryte sdk and IDE.



  • Hi,

    I recently got my maix board, and I can compile and link the C examples that come with the kendryte ide, but I fail to compile C++ programs.
    This is what I tried to compile:

    #include <iostream>
    
    int main()
    {
        std::cout << "Hi!" << std::endl;
    }
    

    I put it in a file named main.cpp.
    This is the compile output and errors:

    [ INFO] Run cmake build:
    [ INFO] [ 93%] Built target kendryte-standalone-sdk
    [ INFO] Scanning dependencies of target hello_world
    [ INFO] [ 96%] Building CXX object CMakeFiles/hello_world.dir/src/main.cpp.obj
    [ INFO] [100%] Linking CXX executable hello_world
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib/libstdc++.a(eh_globals.o): in function `.L0 ':
    [ INFO] eh_globals.cc:(.text.startup._GLOBAL__sub_I___cxa_get_globals_fast+0x3c): undefined reference to `__dso_handle'
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: eh_globals.cc:(.text.startup._GLOBAL__sub_I___cxa_get_globals_fast+0x5a): undefined reference to `__dso_handle'
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib/libstdc++.a(system_error.o): in function `.L0 ':
    [ INFO] system_error.cc:(.text.startup._GLOBAL__sub_I__ZSt20__throw_system_errori+0x2): undefined reference to `__dso_handle'
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: system_error.cc:(.text.startup._GLOBAL__sub_I__ZSt20__throw_system_errori+0x1e): undefined reference to `__dso_handle'
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: CMakeFiles/hello_world.dir/src/main.cpp.obj: in function `.L0 ':
    [ INFO] main.cpp:(.text+0x78): undefined reference to `__dso_handle'
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib/libstdc++.a(cxx11-ios_failure.o):cxx11-ios_failure.cc:(.text._ZN12_GLOBAL__N_122__io_category_instanceEv+0x2a): more undefined references to `__dso_handle' follow
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: hello_world: hidden symbol `__dso_handle' isn't defined
    [ INFO] /home/tim/Downloads/KendryteIDE/LocalPackage/toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: final link failed: bad value
    [ INFO] collect2: error: ld returned 1 exit status
    [ INFO] make[2]: *** [CMakeFiles/hello_world.dir/build.make:85: hello_world] Error 1
    [ INFO] make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/hello_world.dir/all] Error 2
    [ INFO] make: *** [Makefile:84: all] Error 2
    [ INFO] 
    [ INFO] Build Error: /home/tim/Downloads/KendryteIDE/LocalPackage/cmake/bin/cmake exited with code 2.
    

    It for some reason has some problem with __dso_handle, does anyone know how to fix this?
    Is c++ even supported in the first place?

    Thanks!



  • Add "void * __dso_handle = 0;", then it's ok.



  • undefined reference to `__dso_handle' can be partially bypassed as follows:
    void * __dso_handle = 0;

    Some problems can be solved by adding arguments for ld:
    -Wl,--start-group
    -lc
    -lgcc
    -lm
    -Wl,--end-group



  • 有人解决了么,有的话,告诉一声?