This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

use c++ for nrf51 in keil

hello there i want to use c++ library in nrf51dk project. i am using sdk12. i change main.c to main.cpp but i am getting error.uart_original.rar

i have uploaded code here. In abc.cpp file i declared like

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"

#ifdef __cplusplus
}
#endif

but i am getting compiler error. can you tell me how to solve it??

Parents
  • Hi

    All you have to do to allow C++ in a file is to configure that file as a C++ file (renaming it to .cpp is not strictly necessary):
    image description

    As for your code example, why are you including the .cpp files from main.cpp? The .h files should be included, and the .cpp files should be added to your code project.

    Looking at the code your issues don't seem to be C++ related as much as related to linking issues (not including the right files at the right places).

    Best regards
    Torbjørn

Reply
  • Hi

    All you have to do to allow C++ in a file is to configure that file as a C++ file (renaming it to .cpp is not strictly necessary):
    image description

    As for your code example, why are you including the .cpp files from main.cpp? The .h files should be included, and the .cpp files should be added to your code project.

    Looking at the code your issues don't seem to be C++ related as much as related to linking issues (not including the right files at the right places).

    Best regards
    Torbjørn

Children
Related