std::string use, undefined reference to `_exit', etc?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A weird one.

Normally I don't use C++ but figured I would take a stab at it but ran into this perculiar error when linking:

undefined reference to `_exit'

Also _close, _fstat,_isatty,_lseek,_read,_sbrk, etc etc...

 

All I have to do to a breand new project is add the following:

#include <string>
using namespace std;

and in main()

 

string mystring = "string";

 

And I get the linker errors about _exit and friends.

I don't need to use things like string so this is more of a curiousity question.

What is going wrong here?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a similar issue many years ago. It is wanting some operating system hooks. Most of these are just stubs.
Unfortunately I can’t quite recall how to fix it - I do know that if you Google adding printf you’ll find a solution. Or get an example project that uses printf and look to see what files/options it pulls in.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That gave me the hint. Thanks.

 

Just for those playing along... but keep in mind this is going to grow the size of the application quite substantially.... this seems to resolve the linker errors:

1. Untick "use size optimized library" under ARM/GNU Linker

2. Change 'additional specs' under ARM/GNU Linker to 'Use  syscall stubs'

3. In the "Device_Statup" directory there are linker scripts with names like [mcu part number]_flash.ld and _sram.ld

Change..

_end = . ;

to

end = . ;

 

And enjoy your absurdly large application :)

on an ATSAML22N18A you end up with..

Program Memory Usage     :    83332 bytes   30.8 % Full

Data Memory Usage         :    11032 bytes   33.7 % Full

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Glad you found a solution. Something is NQR if you're getting such bloat - even an Arduino build (which is C++) isn't that bloaty.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got rid of it (probably should have kept that test project just a tad longer) but I may have increased debugging to max.

I made a new test project and it ended up a lot smaller. 

I may have done something like that or ticked some other thing without realising it.