Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `_exit' #48

Open
ccchiu opened this issue Jan 24, 2013 · 4 comments
Open

undefined reference to `_exit' #48

ccchiu opened this issue Jan 24, 2013 · 4 comments

Comments

@ccchiu
Copy link

ccchiu commented Jan 24, 2013

I'm use Mac OSX 10.8 , after I installed the summon-arm-toolchain, I tried to build project "https://github.com/nabilt/STM32F4-Discovery-Firmware" for test.
But It shows the following messages.

/Users/mac/sat/lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function exit': /Users/mac/WORK/STM32/summon-arm-toolchain/build/arm-none-eabi/newlib/libc/stdlib/../../../../../gcc-linaro-4.7-2013.01/newlib/libc/stdlib/exit.c:65: undefined reference to_exit'
collect2: error: ld returned 1 exit status

@bklippenstein
Copy link

I ran into a similar problem with my system on Linux.
It's an issue with not linking all the bits of Newlib. Check to make sure that you're including libc.a in your build. You might also need to write a stub for exit and a few other functions. Check the Newlib documentation.

@mmattila
Copy link

After upgrading my toolchain with the newest summon the linker started complaining about missing stubs. It seems that it stems from libgcc division routines being compiled with exceptions enabled. There's a patch in summon (patch-libgcc-divide-exceptions.diff) which - at least for me - does not take care of the problem. Editing the patch to also change "-fnon-call-exceptions" to "-fno-non-call-exceptions" seems to work.

@bolorkhuu
Copy link

Hello!
i have the same problem on mac os x 8.5 , how did you solve this?

@bolorkhuu
Copy link

solved. :)
http://stackoverflow.com/questions/9632595/compiling-basic-c-file-for-the-arm-processor

in your main.c include syscalls.h
Good Luck!

#ifndef SYSCALLS_H
#define SYSCALLS_H

/****************************************************************************

  • Copyright (c) 2009-2012 by Michael Fischer. All rights reserved.
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted provided that the following conditions
  • are met:
    1. Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.
    
    1. Redistributions in binary form must reproduce the above copyright
  • notice, this list of conditions and the following disclaimer in the
    
  • documentation and/or other materials provided with the distribution.
    
    1. Neither the name of the author nor the names of its contributors may
  • be used to endorse or promote products derived from this software
    
  • without specific prior written permission.
    
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  • "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  • LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  • FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  • THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  • INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  • BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  • OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  • AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  • OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  • THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  • SUCH DAMAGE.

  • History:
  • 28.03.2009 mifi First Version, based on the original syscall.c from
  •                newlib version 1.17.0
    
  • 03.06.2012 mifi Changed _write_r and _sbrk_r. Added __putchar and use
  •                __HeapLimit to check end of heap.
    
  • 02.02.2013 nifi Added _exit, _kill and _getpid.
    ****************************************************************************/

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

extern void __putchar (char ch);

/***************************************************************************/

/*int _read_r (struct _reent *r, int file, char * ptr, int len)
{
r = r;
file = file;
ptr = ptr;
len = len;

errno = EINVAL;
return -1;

}
/
/
*************************************************************************/
/

int _lseek_r (struct _reent *r, int file, int ptr, int dir)
{
r = r;
file = file;
ptr = ptr;
dir = dir;

return 0;

}
/
/
*************************************************************************/
/

int _write_r (struct _reent *r, int file, char * ptr, int len)
{
r = r;
file = file;
ptr = ptr;

#if 0
int index;

/* For example, output string by UART */

/* for(index=0; index<len; index++)
{
if (ptr[index] == '\n')
{
__putchar('\r');
}

    __putchar(ptr[index]);
}

#endif

return len;

}

/
/
**************************************************************************/

int _close_r (struct _reent *r, int file)
{
return 0;
}

/***************************************************************************/

/***************************************************************************/

int _fstat_r (struct _reent *r, int file, struct stat * st)
{
r = r;
file = file;

memset (st, 0, sizeof (* st));
st->st_mode = S_IFCHR;
return 0;

}

/***************************************************************************/

int _isatty_r (struct _reent *r, int fd)
{
r = r;
fd = fd;

return 1;

}

/***************************************************************************/

void _exit (int a)
{
a = a;

while(1) {};

}

/***************************************************************************/

int _kill (int a, int b)
{
a = a;
b = b;

return 0;

}

/***************************************************************************/

int _getpid(int a)
{
a = a;

return 0;

}

/*** EOF ***/

#endif /* SYSCALLS_H */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants