gold_marigold55
04-26-2005, 01:34 AM
Hi,
I called alloca () in my program and comes out with undefined symbol error. I have put #include <stdlib.h> in my file and also loaded the stdlib with -lstdlib but still got that error.
I searched man page and it indicates that in stdlib.h.
Can't find out the reason.
Thanks,
gold_marigold
RobSeace
04-26-2005, 12:41 PM
Well, sometimes man pages lie to you... ;-) But, in this case, just assuming you're
working on a glibc-based system, you will need to define _GNU_SOURCE prior to
including your headers, in order for it to define a lot of non-standard/optional things
such as this... So, try adding a "#define _GNU_SOURCE 1" line prior to any #include
statements you do (or, compile with "-D_GNU_SOURCE=1")...
Oh, and generally there is no actual separate "stdlib" library, which you need to link
in, either... Just including the header file should be all you need... The reason you
get an undefined symbol is because there is no real alloca() function; its behavior
can't be implemented via any real function, but really has to be a built-in compiler
feature (or maybe some inline assembly code), in order to work... When you include
the proper headers with the proper definitions, alloca() will likely be defined as a
macro for __builtin_alloca(), and that's what'll be really called... (And, that, in turn
will simply output the appropriate assembly code to grow the stack as needed...)
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.