I have a project with only C code that compiles and has been working on for years. Lately, there was a need to add some more functionality that requires some C++ code so I added a small C++ test code to see if it would work. This is what I added:
events.h
#ifndef _EVENTS_H #define _EVENTS_H #include <stdint.h> #ifdef __cplusplus extern "C" { #endif void evtAddCurrent(const float current); #ifdef __cplusplus } #endif #endif
events.cpp
#include <vector> #include "events.h" static std::vector < float > current_values; void evtAddCurrent(const float current) { current_values.push_back(current); }
Then I include the events.h in one of my .c files. I add the --cpp11 flag only to the events.cpp file because if I add that to the whole project then I get about 350 errors. When I do this, the project compiles just fine but now the code doesn't work at all. I don't know if it gets corrupted and why. I have no idea what is happening.
I'm working with NXP MQX RTOS and I don't know if there are one or more files I should be adding or some other configurations I should be performing on my project for it to work. I repeat, the code compiles just fine but the code doesn't run at all (and I'm not even calling the C++ function, just adding the code to the compilation and linking). I can even verify that the c++ function is present on the resulting image by looking at the map file.
Does anyone know what could be happening? What am I missing?
This is my environment:
IDE-Version:µVision V5.26.2.0Copyright (C) 2018 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information:Flex license: MDK-ARM Plus: 3 user(s) (mdk_plus)Support: Nov 2018
Tool Version Numbers:Toolchain: MDK-ARM Plus: 3 user(s) Version: 5.26.2.0Toolchain Path: C:\Keil_v5\ARM\ARMCC\BinC Compiler: Armcc.exe V5.06 update 6 (build 750)Assembler: Armasm.exe V5.06 update 6 (build 750)Linker/Locator: ArmLink.exe V5.06 update 6 (build 750)Library Manager: ArmAr.exe V5.06 update 6 (build 750)Hex Converter: FromElf.exe V5.06 update 6 (build 750)CPU DLL: SARMCM3.DLL V5.26.2.0Dialog DLL: DCM.DLL V1.17.2.0Target DLL: UL2CM3.DLL V1.161.6.0Dialog DLL: TCM.DLL V1.36.1.0
You should then debug it and see what is going on.