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

'undefined reference to ....' when I'm working with class

Hy to everyone

I'm working with SDK15.3 Ble_Blinky example for my nRF52840 Dongle (pca10059).

First to know, I'm wokring with c++ and the whole Project is compiling without any errors.

I added a test class and included it in the main.cpp and also everything worked well.

Then I made an instance of my test1 class and got the error :

03:14:15 **** Incremental Build of configuration Default for project RobEx ****
make all 
Compiling file: main.cpp
./main.cpp:562:13: warning: 'void idle_state_handle()' defined but not used [-Wunused-function]
 static void idle_state_handle(void)
             ^~~~~~~~~~~~~~~~~
Linking target: _build/nrf52840_xxaa.out
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: _build/nrf52840_xxaa/main.cpp.o: in function `main':
/home/sevko/Documents/RobEx//./main.cpp:590: undefined reference to `Test1::Test1()'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/sevko/Documents/RobEx//./main.cpp:590: undefined reference to `Test1::~Test1()'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/sevko/Documents/RobEx//./main.cpp:590: undefined reference to `__cxa_end_cleanup'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: _build/nrf52840_xxaa/main.cpp.o:(.ARM.extab.text.startup.main+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
make: *** [_build/nrf52840_xxaa.out] Error 1
components/toolchain/gcc/Makefile.common:292: recipe for target '_build/nrf52840_xxaa.out' failed
"make all" terminated with exit code 2. Build might be incomplete.

My Test1 class :

//=====TEST1.H======
#ifndef TEST1_H_
#define TEST1_H_
class Test1 {
public:
	Test1();
	virtual ~Test1();
	void foo();
};

#endif /* TEST1_H_ */
//=====TEST1.CPP======
#include "Test1.h"
Test1::Test1() {
	// TODO Auto-generated constructor stub

}
Test1::~Test1() {
	// TODO Auto-generated destructor stub
}
void Test1::foo(){

}

My main.cpp:

int main(void)
{
    // Initialize.
    log_init();
    leds_init();
    timers_init();
    buttons_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    // Start execution.
    NRF_LOG_INFO("Blinky example started.");
    advertising_start();

    Test1 tst;  
 //   tst.foo();
    // Enter main loop.
    for (;;)
    {
    	for(int i = 0 ; i < LEDS_NUMBER ; i++){
        bsp_board_led_invert(i);
        nrf_delay_ms(250);
    	}
        //idle_state_handle();
    }
}

The Test1.cpp and Test1.h are in the same Folder as main.cpp.

I'm not sure if it's a compiler Problem or a software Problem, because I'm using c++ with c code, but maybe someone had a similar error.

Greetings N3210

PS: I had a look on this site https://stackoverflow.com/questions/6045809/link-error-undefined-reference-to-gxx-personality-v0-and-g

I think the compiler somehow doesn't compile in c++. Maybe i have to change something in the Makefile.common.

Parents Reply Children
No Data
Related