Thanks for all feedbacks.
@marcov - I have two functions with different names declared, one as external, the other standard.
The second has an dummy code in implementation and can be compiled.
@TRon - two functions with different names: function monarco_init_
1 and function monarco_init.
@Thaddy - the two different calling declarations are just in case. It has to run on Raspberry Pi. I do the most of coding and syntax tests on a win system.
In the mean time I found the problem.
unit call_monarco;
// *****************************************************************************
// * @file monarco.h
// * @brief libmonarco - Main API
// *****************************************************************************
// * @section License
// * Copyright REX Controls s.r.o. http://www.rexcontrols.com
// * Author: Vlastimil Setka
// * This file is covered by the BSD 3-Clause License
// * see LICENSE.txt in the root directory of this project
// *****************************************************************************
//
//
//
{$H+}
{$BITPACKING ON}
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
interface
uses
Classes, SysUtils, monarco_structure;
//{$I stdinth.inc}
Const
MONARCO_SDC_ITEMS_SIZE = 256;
type
Platfrm = Pchar;
pPlatfrm = ^platfrm;
Const
// Library name
{$IFDEF MSWINDOWS}
monarcolib = 'monarco.dll';
{$ELSE}
monarcolib = 'monarco.so'; // valid for all Unix platforms
{$ENDIF}
{
* Monarco Initialization
* Connect to `*spi_device` with `spi_clkfreq` clock frequency (Hz)
* and provide some `*platform` data - for generic linux platform it is a debug print prefix.
int monarco_init(monarco_cxt_t *cxt, const char *spi_device, uint32_t spi_clkfreq, void *platform);
}
function monarco_init(var cxt: monarco_cxt_t; spi_device: Pchar; spi_clkfreq: Dword; platform: pPlatfrm): Integer;
{$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
{
* Monarco Main
* Performs one SPI transaction with Monarco HAT - exchange of complete input and output process data
* and single new service data reqeust and response to previous request.
* Have to be called periodically, at least faster than process data watchod timeout (default 100 ms)!
int monarco_main(monarco_cxt_t *cxt);
}
function monarco_main(var cxt: monarco_cxt_t): Integer;
{$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
{
* Monarco Cleanup
* Free all resources allocated by `monarco_init()`.
int monarco_exit(monarco_cxt_t *cxt);
}
function monarco_exit(var cxt: monarco_cxt_t): Integer;
{$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
implementation
function monarco_init; external monarcolib name 'monarco_init';
function monarco_main; external monarcolib name 'monarco_main';
function monarco_exit; external monarcolib name 'monarco_exit';
end.
It was the compiler switch, the code can be compiled without error.
When I added a new unit with File - new Unit, the switch {$mode ObjFPC} is automatically set, compile fails.
If I omit it it fails too.
Error Message:
call_monarco.pas(129,24) Fatal: Syntax error, ":" expected but ";" found
This was the reason for me to duplicate the function definition.
If i use {$MODE DELPHI} it passes.
I heavily use another library on Windows systems and Raspberries, snap7 and have copied the definitions from there but overlooked the compiler switch.
When I place all function declaration information before
implementation and omit it after implementation it works too with {$mode ObjFPC}