Hi Guys,
I have some code I have written in C (header file called lazspi.h and c file called lazspi.c) which I have compiled using gcc with the -lm flag.
I have successfully managed to include the .o file and use the functions in my pascal Application. (using
ftp://ftp.freepascal.org/fpc/docs-pdf/CinFreePascal.pdf) The problem (or annoying more than anything) is that I have to always make some sort of change (like delete an empty line, or add an empty line) to the pascal unit which is using the .o file before the compiler will successfully recompile, otherwise i get "undefined reference to (method name)" error for each method being linked to in the .o file. It always seems to be for the last method using the external C methods.
- Run compile
- Successful compile
- Stop run
- Run compile
- Get Errors shown below
- Add a line or remove a line from the lazspi unit
- Run compile
- Successful compile
Errors in messages window:
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
../lib/arm-linux/lazspi.o: in Function 'SENDMOTORPOS':
../lazspi.pas:70: undefined reference to 'Select_ADC1'
../lazspi.pas:73: undefined reference to 'get_ADC'
../lazspi.pas:73: undefined reference to 'Select_ADC0'
../lazspi.pas:73: undefined reference to 'get_ADC'
../lazspi.pas:70: undefined reference to 'init_cs_pins'
../lazspi.pas:71: undefined reference to 'spi_init'
../lazspi.pas:71: undefined reference to 'SendMPos'
ProgramName.ipr(28)Error: Error while linking
ProgramName.ipr(28)Fatal: There were 1 errors compiling module, stopping
Im using this unit in a large program so having to navigate to it and tap enter or delete before checking changes gets tiresome.
Im running Lazarus V1.2.4 (fpc V2.6.4) on an Olimex A20 (Allwinner A20 CPU) with Linux (Debian Jessie)
Can anyone point out something that may cause this?
I have included the lazspi.h header file and the pascal unit function declarations. I have left out the lazspi.c file
lazspi.h C file
ifndef LAZSPI_H
#define LAZSPI_H
int spi_init();
void init_cs_pins() ;
int get_ADC(int fd) ;
void Select_ADC0() ;
void Select_ADC1() ;
void SendMPos(int Pos) ;
#endif
Lazspi FPC Unit:
unit lazspi ;
{$link lazspi.o}
{$linklib c}
interface
uses
CTypes, math ;
function spi_init : integer; cdecl;external;
procedure init_cs_pins ;cdecl;external;
procedure Select_ADC0 ;cdecl;external;
procedure Select_ADC1 ;cdecl;external;
function get_ADC(fd : integer) integer; cdecl;external;
procedure sendMPos(pos : integer) ; cdecl;external;
{
my own declared methods here
}
implementation
{
my own method implementation here
}
---------------------
end.
Apologies for the long post. Any help would be greatly appreciated.
Thanks in advanced.