lpcware

Undefined reference to Chip_I2C_Init()

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Hackscribble on Sun Sep 21 14:48:07 MST 2014
Hello

Attached cut-down sample code demonstrates the problem.  C++ program uses C++ library.  Member function of the library calls Chip_I2C_Init().  I get linker error "undefined reference to `Chip_I2C_Init'test-lib.cpp/test-lib/srcline 17C/C++ Problem".

If I remove the call to Chip_I2C_Init() from the library and include it in the main function of my program, it links OK.

Any ideas on how to avoid this workaround? 

In my full program, other I2C API and Chip_... calls work OK when called from the library functions.  Only Chip_I2C_Init() is giving an error.

I'm using v7.3.0 of the IDE and v2.06 of LPCOpen for 11u68.

Many thanks

Ray

// test-lib.h
#ifndef TEST_LIB_H_
#define TEST_LIB_H_

#include "board.h"
#include "cr_section_macros.h"

class testClass
{
public:
testClass();
void begin();
};

#endif /* TEST_LIB_H_ */


// test-lib.cpp
#include "test-lib.h"

testClass::testClass()
{

}

void testClass::begin()
{
Chip_I2C_Init(I2C0);
}


// test-prog.cpp
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include <cr_section_macros.h>

#include "test-lib.h"

testClass footy;

int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

    footy.begin();

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
}


Outcomes