Does the Kendryte SDK support C++?


#1

Hi!

Recently got my maix M1 board with lcd and camera and can write C programs for it, but not C++.
This is the program I tried:

#include <iostream>
int main()
{

std::cout << "Hi!" << std::endl;

}

And when I compile it in the kendryte IDE, it keeps giving me undefined reference errors e.g.:

system_error.cc:(.text.startup._GLOBAL__sub_I__ZSt20__throw_system_errori+0x2): undefined reference to `__dso_handle'

When I compile it directly with the toolchain it gives me lots of errors like these:

/home/tim/Desktop/maixSDK/kendryte-toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: /home/tim/Desktop/maixSDK/kendryte-toolchain/bin/../lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-fclose.o): in function `.L7':
fclose.c:(.text._fclose_r+0x9c): undefined reference to `pthread_setcancelstate'

How would I fix this? Is C++ even supported?

Thx!


#2

Yes you can use C++. I have just uploaded some code to allow the use of the Adafruit_GFX code which is C++, see here.
During programming I have had the same errors as you have. I somehow fixed them but I can’t remember how. I am trying to reproduce them, but can’t. What I did do was add the -fpermissive flag (see my github stuff). Also if you add/remove files you need to redo the cmake thing again instead of only make. Keep trying.


#3

Thanks for your reply! I tried adding the -fpremissive flag, but it didn’t work unfortunately. This is the command I ran if it helps:

'/home/tim/Desktop/maixSDK/kendryte-toolchain/bin/riscv64-unknown-elf-g++' -fpermissive main.cpp

Maybe this helps reproducing it? DO you see anything wrong with the command?

I btw like the idea of using adafruit_gfx! It has some very good graphics functionality! Thanks for sharing.
Thanks!


#4

I do not use the compilers directly. Instead I followed the usage of kendryte-standalone, with the added flag in kendryte-standalone-sdk/cmake/compile-flags.cmake:

add_compile_flags(CXX -std=gnu++17 -fpermissive)

The actual call to the compiler is very complicated. It has dozens of flags and other things.
Is everything you need included in that compiler call? No additional libraries or include files in other locations?


#5

Using kendyte standalone worked! But I’m highly confused, what did the standalone sdk do that makes it work, because I can’t compile c++ applications with the kendryte ide either!

Another weird thing, it links my c++ program as a C executable. But whatever, it works!

Thanks for your help!


#6

Yesterday I came across this page. At about 1/3 of the page it seems to suggest that for C++ some properties must be set. I do not use the IDE myself, so I haven’t tested this.