undefined reference to operator new

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

undefined reference to operator new

1,079 Views
aaronminner
Contributor III

Using MCUXpresso with SDK 2.5.0 for the K66 processor.  Started with a C project that I got to compile, link and execute on the hardware just fine. Added a C++ file to provide support for an external device (SI5351A clock chip).  Updated the build process, since it doesn't consider C++ files automatically.  Resolved the few syntax errors involved in calling C++ from C.  So far, so good.  However, in the link stage, I get the following error:

> ... undefined reference to `operator new(unsigned int)'

If I follow the advice from the Internet and add "stdc++" to the link options, I get a list of errors related to exceptions.  If I try to add other linkage options to resolve those, I get additional errors.  I did clean the project at various stages and build fresh; doesn't seem to make a difference.

Am I overlooking something in incorporating C++ from within a C project in MCUXpresso?

0 Kudos
Reply
1 Reply

961 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Aaron Minner ,

- First method,In MCUXpresso IDE, you also can create C++ project:

pastedImage_1.png

- Second, please check which library your project used, the default lib of SDK demo use Redlib, this library doesn't

support C++. So change it to NewlibNano or Newlib:

pastedImage_2.png

Hope it helps,


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply