-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
g++ (C++) support #5
Comments
The minimal changes necessary to make it compile are: Change "CFLAGS += -W -Wall --std=gnu++11 -Os" Then wrap entire code of the startup file in extern "C" { .... } This would compile, but will not support exceptions. If you want exceptions, then you need to remove the corresponding CFLAG and modify the linker script to incide exidx definitions. You can look at more complete linker script examples to see how it is done there. |
Thanks. That worked. Should the
rule be modified to work with .cpp file extension as well? |
That depends on your file extensions. If you use cpp, then yes. |
I've changed the makefile accordingly (gnu++11, no exceptions, etc) and adjusted the code for my specific samd21 and board. EDIT: I've just added extern "C" to the functions in main.cpp except main (that is, sys_init(), uart_puts(), uart_init(), timer_init(), etc.). I understand that the C++ compiler was mangling their names, and surely main() was not being able to find them and thus the program was not working. Thus the extern "C" directive fixes it. But this confuses me a little bit, will I need to add extern "C" to every single function and file with code I create? Why is main(), or rather the linker, not being able to find the mangled names?
|
The issue here is that irq_handler_tc1 is not recognized as a strong substitute for a weak alias. So it looks like your only solution is to define actual dummy implementations for all the handlers, and then you can remove extern stuff. |
The minimal fix is to add extern "C" around irq_handler_tc1() alone. |
That seems to work as a minimal fix and everything compiles and runs fine. I assume that wrapping will be required for all future interrupt handlers that I implement as well, but for now, there's no need to define dummy implementations for all the handlers as the compiler doesn't complain because it finds irq_handler_dummy() on the startup.c file right? |
Compiler does not complain because weak aliases are not implemented in C++ mode. So when an interrupt handler like this is compiled in C++ mode, it is just removed as an unused function. If I were doing this for a real project, I would make a dummy version of each handler and remove the weak alias attributes. This would let you compile everything in C++ mode and will generate errors when you redefine the existing dummy handler. So you won't have to spend as much time debugging when you inevitably forget extern around one of the handlers. |
Hi,
I've been using the projects, and they work very well. I'm specifically using /tree/master/samd21 , and I was wondering what would be necessary to have C++ support, using for example the arm-none-eabi-g++ compiler.
When changing to that compiler I get the following errors in the vector table definitions:
makefile
errors:
Thank you
The text was updated successfully, but these errors were encountered: