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

Compiling C and C++ code

We've currently only been developing our application in C. We now have a couple of C++ libraries we'd like to use and are having trouble compiling the mixture of C and C++ code.

This is the Makefile: http://pastebin.com/M4Wsybxt And this is the output when I run make: http://pastebin.com/4SmrvJuz

All the #include statements are wrapped in an extern "C" block.

The code that is causing the code to not compile seems to be this (from main.cpp file):

static void gpio_config() {
    ret_code_t err_code;
     
    // Initialize driver
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
     
    // Configure output pins for LEDs
    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
    err_code = nrf_drv_gpiote_out_init(LED_RED, &out_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_out_init(LED_BLUE, &out_config);
    APP_ERROR_CHECK(err_code);
     
    // Set output pins
    nrf_drv_gpiote_out_set(LED_RED);
    nrf_drv_gpiote_out_set(LED_BLUE);
     
    // Turn leds off
    nrf_drv_gpiote_out_toggle(LED_RED);
    nrf_drv_gpiote_out_toggle(LED_BLUE);
     
    /* No inputs for now */
}

It seems like the compiler might be ignoring the extern "C" statement, since I get the same error if I leave that out.

I'm currently using the arm-none-eabi-g++ compiler, but also tried arm-none-eabi-c++ with no difference.

Could anyone help me get on the right track to compiling this C and C++ code? I'd rather not have to change the NRF SDK code to make this compile.

Related