i am using Keil uVision3 + ADUC7026, i am trying to allocate #include <ADuC7026.h> #include "stdio.h" #include "stdlib.h" unsigned char memory_pool[0x400]; int main (void) { int *i; init_mempool (memory_pool, sizeof(memory_pool)); i = malloc(sizeof(int)); } warning: implicit declaration of function 'init_mempool' .......... error: undefined reference to 'init_mempool' can someone help me ,why can't find init_mempool? "Do not use Standart Libriries" is uncheckt. and the system can find malloc. thanks
The compiler warning ("implicit declaration") is because you have not supplied a prototype for the function. Usually this would come from a header file. It is not a standard C function, so stdlib.h won't do. As for the linker error ("undefined reference"), did you build and link init_mem.c with the rest of your program? This function is optional, since so many 8051 systems do without malloc(), and there's no need to have it taking up space in them all.
thank you for your help, your tips are very helpful. i am trying to link INIT_MEM now,but error again: INIT_MEM.c(42): error: undefined reference to '__mp__', even there is a definition: extern struct __mp__ *__mp__; confused...
I just tried your example with the latest release of the ARM tools and everything worked as expected. No errors or warnings are generated. What version are you using? Jon
i've just tried. ARM Version 1.5(Evaluation) + GCCARM331. (from http://www.keil.com/demo/eval/arm.htm ). but the problem is not gone.
Well, that's the same version I used and the following compiled just fine.
#include <ADuC7026.h> #include "stdio.h" #include "stdlib.h" unsigned char memory_pool[0x400]; int main (void) { int *i; init_mempool (memory_pool, sizeof(memory_pool)); i = malloc(sizeof(int)); while (1); }
thanks Jon, thanks Drew. problem solved. i used GNU, hence the problem...
When you start an ARM project, you should first to select the compiler (Keil CARM, GNU, or ARM ADS/RealView) you want to use. init_mempool is only part of the Keil CARM Compiler run-time library. For using this function, it is required that you setup a project using the Keil CARM compiler. See Getting Started User's Guide (GSA.CHM, Development Tools, Select the Toolset). For using malloc with Keil CARM you need to call the init_mempool function. See: http://www.keil.com/support/man/docs/ca/ca_init_mempool.htm For using malloc with GNU Compiler you need a more complex setup. See example: Keil\ARM\GNU\Examples\Memory. However, due to the nature of the GNU run-time library (it has a clustering of 32KB and requires a minimum RAM of 32KB) you cannot use malloc on single chip devices. Therefore you should consider to use the Keil CARM compiler instead, since the run-time library is designed for single chip systems. Reinhard