<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Undefined reference to Chip_I2C_Init() in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577135#M19554</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Mon Sep 22 14:46:43 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I had checked that early on.&amp;nbsp; Highlighted the function name in my code, right click, searched workspace.&amp;nbsp; Found the function in the library.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And cutting and pasting the function call to move it from my library to main cleared the error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 20:17:24 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T20:17:24Z</dc:date>
    <item>
      <title>Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577129#M19548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Sun Sep 21 14:48:07 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached cut-down sample code demonstrates the problem.&amp;nbsp; C++ program uses C++ library.&amp;nbsp; Member function of the library calls Chip_I2C_Init().&amp;nbsp; I get linker error "undefined reference to `Chip_I2C_Init'test-lib.cpp/test-lib/srcline 17C/C++ Problem".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas on how to avoid this workaround?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my full program, other I2C API and Chip_... calls work OK when called from the library functions.&amp;nbsp; Only Chip_I2C_Init() is giving an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using v7.3.0 of the IDE and v2.06 of LPCOpen for 11u68.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ray&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;// 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_ */&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;// test-lib.cpp
#include "test-lib.h"

testClass::testClass()
{

}

void testClass::begin()
{
Chip_I2C_Init(I2C0);
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;// test-prog.cpp
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include &amp;lt;cr_section_macros.h&amp;gt;

#include "test-lib.h"

testClass footy;

int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read clock settings and update SystemCoreClock variable
&amp;nbsp;&amp;nbsp;&amp;nbsp; SystemCoreClockUpdate();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up and initialize all required blocks and
&amp;nbsp;&amp;nbsp;&amp;nbsp; // functions related to the board hardware
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_Init();
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set the LED to the state of "On"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_LED_Set(0, true);
#endif
#endif

&amp;nbsp;&amp;nbsp;&amp;nbsp; footy.begin();

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Force the counter to be placed into memory
&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile static int i = 0 ;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enter an infinite loop, just incrementing a counter
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i++ ;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577129#M19548</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577130#M19549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Sun Sep 21 14:58:55 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Use extern "c" around the function definition. If you don't understand, look it up!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577130#M19549</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577131#M19550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Sun Sep 21 15:51:47 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you mean the definition of Chip_I2C_Init()?&amp;nbsp; That is defined in the LPCOpen file "i2c_11u6x.h" and it does have extern.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;#ifndef __I2C_11U6X_H_
#define __I2C_11U6X_H_

#include "i2c_common_11u6x.h"

#ifdef __cplusplus
extern "C" {
#endif

// snip

/**
 * @briefInitializes the LPC_I2C peripheral with specified parameter.
 * @paramid: I2C peripheral ID (I2C0, I2C1 ... etc)
 * @returnNothing
 */
void Chip_I2C_Init(I2C_ID_T id);

// snip


/**
 * @}
 */

 #ifdef __cplusplus
}
#endif

#endif /* __I2C_11U6X_H_ */&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577131#M19550</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577132#M19551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by lpcxpresso-support on Sun Sep 21 23:52:00 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are writing C++ but calling C functions, you need to tell the compiler which functions use C linkage. You do this by using&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;extern "c"&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;around your C functions or (more typically) around the include files that have C linkage. e.g.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;extern "c" {
#include "board.h"
#inlcude other_c_linkage_headers.h
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;See &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F1041866%2Fin-c-source-what-is-the-effect-of-extern-c" rel="nofollow noopener noreferrer" target="_blank"&gt;http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this isn't the problem, you may not be linking with the correct library (Debug vs Release?)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577132#M19551</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577133#M19552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Mon Sep 22 13:20:37 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the suggestions, lpcxpresso-support.&amp;nbsp; The C function in question is an LPCOpen function.&amp;nbsp; The LPCOpen library file already has extern "C" in it (see extract in reply 2 above).&amp;nbsp; However, I've added further extern "C"s in my library and program files, but no difference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I find interesting is that it is specifically Chip_I2C_Init which triggers the problem.&amp;nbsp; My library also calls the following LPCOpen functions (also presumably written in C) without problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_I2C0);
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 4, (IOCON_FUNC1 | I2C_FASTPLUS_BIT) | IOCON_DIGMODE_EN);
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 5, (IOCON_FUNC1 | I2C_FASTPLUS_BIT) | IOCON_DIGMODE_EN);
Chip_SYSCTL_PeriphReset(RESET_I2C0);&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since my last post, I found a workaround.&amp;nbsp; By looking at the source code for Chip_I2C_Init, I worked out that I could replace it with the calls to Chip_Clock_EnablePeriphClock and Chip_SYSCTL_PeriphReset.&amp;nbsp; The code compiles, links and works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ray&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577133#M19552</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577134#M19553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Mon Sep 22 13:36:13 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;It makes me wonder if you spelt the function name correctly...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577134#M19553</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577135#M19554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Mon Sep 22 14:46:43 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I had checked that early on.&amp;nbsp; Highlighted the function name in my code, right click, searched workspace.&amp;nbsp; Found the function in the library.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And cutting and pasting the function call to move it from my library to main cleared the error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577135#M19554</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Undefined reference to Chip_I2C_Init()</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577136#M19555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Hackscribble on Wed Sep 24 03:40:37 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem solved.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my project's properties, I needed to move my library to the top of the library lists, so that it was above the chip library.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was in Quick Settings - Library Search Paths and Quick Settings - Libraries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help, Fall Guy and lpcxpresso-support.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ray&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 20:17:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Undefined-reference-to-Chip-I2C-Init/m-p/577136#M19555</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T20:17:24Z</dc:date>
    </item>
  </channel>
</rss>

