I created a new project( CHOOSING THE library function) and write the code :
#include<stdio.h>
//signed long int pow(signed int base, signed int power) signed long int pow(signed int base, signed int power); signed long int pow(signed int base, signed int power) { signed long int result_pow = 1; for(;power>0;power--) { result_pow = result_pow * base; } return(result_pow); }
this generated a power.lib as library file after building . Now I created a header file with the code :
#ifndef __power_h #define __power_h
#endif
Now I m having the error : Power.axf: Error: L6218E: Undefined symbol main (referred from rtentry2.o).
=>How to link the new created header file with library file . =>How do i solve this error and HOW TO CREATE A 'C' HEADER FILE FOR 'C' FUCTIONS .
According to that I created a .h file ad write the code as :-
#include<stdio.h> extern signed long int pow(signed int base, signed int power); signed long int pow(signed int base, signed int power) { signed long int result_pow = 1; for(;power>0;power--) { result_pow = result_pow * base; } return(result_pow); }
and then i added this header file in my main C file as :-
#include<stdio.h> #include<lpc21xx.h> #include<power.h> int main(void) { signed int si_int = 2; /* initialize the serial interface */ PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */ U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */ U1LCR = 0x03; /* DLAB = 0 */ si_int = pow(si_int,si_int); printf("%ld",si_int); while(1); }
Now it is compiling correctly but when it starts debugging , command winndow shows:
Running with Code Size Limit: 32K Load "C:\\Keil\\Himanshu\\Power\\Power.AXF"
*** Restricted Version with 32768 Byte Code Size Limit *** Currently used: 4108 Bytes (12%)
BS \Power\17 BS \Power\12 BS \Power\11 BS \Power\10 BS \Power\7
And I m not able to see any output on UART . Also when I try to add si_int in watch1 it shows asn error " can't add si_int ". While the command window display the following message :
WS 1,'result_pow _____^ *** error 34: undefined identifier WS 2,'si_int _____^ *** error 34: undefined identifier I checked it number of times but there is no " ' " before si_int .
=> please help me out
"According to that I created a .h file ad write the code as ..."
No. You didn't follow the links contained therein, one of which would have taken you here:
c-faq.com/.../hfiles.html
Function declarations belong in the .h file. Function definitions belong in the .c file.
Thanks alot "Dan Hennry" ad "Andy Neil" , finally I got the output from my first header file . Thnks alot again......