I am looking for a way to call a function of an Inline C block present in a perl file from another file's Inline C block.
I have this perl file that contains the get_instrument_price function inside an Inline C block
package Dev::Instrument::Price;
use warnings 'all';
use strict;
use Inline C => <<'__END_OF_C__';
int get_instrument_price(int type)
{ return 154; }
__END_OF_C__
There's another file that should make a call to the above file to get the instrument price
package Dev::Instument::Detail;
use warnings 'all';
use strict;
use Inline C => <<'__END_OF_C__';
extern int *get_instrument_price(int type);
int get_instrument_detail(int type)
{
# some code
int instrument_price = get_instrument_price(type);
# some more code
}
__END_OF_C__
I have tried using LIBS => '-L/_Inline/lib/auto'
as mentioned in the references below that didn't work for me.
Took references from:
A workaround is to split the common C functions into a separate library, for example:
libinstrument/instrument.c:
libinstrument/instrument.h:
lib/Dev/Instrument/Detail.pm:
lib/Dev/Instrument/Price.pm:
p.pl:
Compile the common library:
Output: