On Mon, 09 Feb 2009, Barry Jackson wrote:
Hi Barry,
> I have a library of functions to control a data acquisition card via USB
> which is written for Linux. I want to access these functions from Harbour.
> Is there a "How To" anywhere that would help me to achieve this?
> I have tried simply calling the functions in my .prg and linking the C
> library, but all the functions are unresolved at link time.
> Undefined reference to `HB_FUN_CLEARALLDIGITAL' etc. etc.
> I have used the same card with xBase++ and xHarbour in Windows using
> functions in an external .dll which work well, but I do not know how to use
> this C library in Linux.
> Any help would be appreciated.
For each function you want to call from external library you have to
create Harbour function as wrapper to the external C function. You
can start using #pragma begindump / #pragma enddump but for final version
I suggest to move C code into separated .c file. F.e. let's create
wrappers to some GLIBC functions:
extern int chmod(const char *path, mode_t mode);
extern mode_t umask(mode_t mask);
The code may look like:
/*** tst.prg ***/
proc main()
? UMASK(0)
? CHMOD( "tst.prg", 420 /* 644 in octal notation */ )
return
/* start C code */
#pragma begindump
/* header files for external functions */
#include <sys/stat.h>
#include <sys/types.h>
/* Harbour functions header file */
#include "hbapi.h"
HB_FUNC( UMASK )
{
hb_retni( umask( hb_parni( 1 ) ) );
}
HB_FUNC( CHMOD )
{
hb_retni( chmod( hb_parc( 1 ), hb_parni( 2 ) ) );
}
/* end of C code */
#pragma enddump
/*** tst.prg EOF ***/
In this code are used Harbour functions hb_par*(), hb_ret*()
In Clipper's NG you can find documentation for extended C API
and _par*()/_ret*() functions which makes the same job as
Harbour ones.
best regards,
Przemek
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour