I recently finished my C bootloader, so when I started to write the main kernel, it seemed obvious to write it in C++.
I have the standard C library working with the needed system calls, but as I started to move to C++, a few errors came up. Mostly linkage errors.
As of now, I have <vector> working, but i still need to use printf for logging purposes, ostream throwing me about 500 lines of linkage errors, and about the same when i just want to have a std::string.
I have a few questions:
- I can see a difference when linking with g++ or ld. g++ throws me errors about vfp arguments, and --verbose tells me it just includes the default lib/ directory, not the lib/fpu/, even when I explicitly pass it as argument, where ld does the job just fine. Any Idea why that is?
- <vector> works when I link with only libc and libm (C standard lib, not C++), but when I try <string>, if i don't link with libstdc++, I get and if I do link with libstdc++, i get 500+ errors. First there is a few errors about multiple definition of the __throw* function (which I overloaded to resolve previous linkage errors), then lots of errors about stack unwinding (?) like __aeabi_unwind_cpp_pr0, and finally undefined references to standard function like fwrite, memcpy, memcmp, wmemset and so on. Every article/book/guide on baremetal C++ says it is a bad idea to have exceptions, where that would be too much for the small embedded targets. Would that be still such a problem on a target like the Raspi? I assume the libstdc++ is built on libc and its system calls, how right is this assumption? And finally, does the order in which the libs are passed to the linker matter?
Code: Select all
obj/kernel.o: In function `main': :(.text+0x94): undefined reference to `std::allocator<char>::allocator()' :(.text+0xb0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' :(.text+0xbc): undefined reference to `std::allocator<char>::~allocator()'
ps: if anyone cares to enlighten me on why every format except %d, %u, and %i works for printf, where those three are only right when printing single digit, please do so.
pps: I'm currently working on the Beaglebone black Bare metal, I have a few example at the moment, check it out: https://github.com/allexoll/BBB-BareMetal