Hi Russel,
As Brad noted, the --dynamic flag will not work with --library (that's a
bug). But if you're okay compiling your Chapel library statically, you
can still link to it.
Here's an example of how to use --library:
*testing.chpl:*
// Chapel file that exports a single function which prints to the console
*export* *proc* foo() {
writeln("I do nothing");
}
*testing.h:*
void foo(void);
*use_testing.c:*
#*include* "testing.h"
*extern* *void* chpl_library_init(*int* argc, *char** argv[]);
*extern* *void* chpl_library_finalize(*void*);
// Test of calling an exported Chapel library.
*int* main(*int* argc, *char** argv[]) {
// Initialize the Chapel runtime and standard modules
chpl_library_init(argc, argv);
// Call the function
foo();
// Shutdown the Chapel runtime and standard modules
chpl_library_finalize();
*return* 0;
}
Note that in order to use a Chapel library file, you will need to
initialize and shut down its copy of the Chapel runtime and standard
modules, using chpl_library_init(int argc, char* argv[]) and
chpl_library_finalize().
*Compilation of .chpl file:*
chpl --library testing.chpl -o libtesting
*or *
chpl --library --static testing.chpl -o libtesting
This will generate libtesting.a.
*Compilation**of use_testing.c:*
gcc use_testing.c -L. -ltesting `$CHPL_HOME/util/config/compileline
--libraries`
Note that this compilation command requires you to have a copy of Chapel
nearby (compileline will be present even with just a Chapel release
tarball).
*Expected output from ./a.out:*
I do nothing
Hope this helps!
Lydia
On 10/16/2017 11:29 AM, Brad Chamberlain wrote:
Hi Russel --
Apologies for the delayed response -- we had some mixed signals
internally as to who was going to handle the response to this thread.
My quick/lazy answer was going to be that 'chpl --library --dynamic'
should cause all 'extern proc' declarations to get bundled into a
'.so' file. But then rather than being lazy, I gave it a quick try,
and it didn't seem to work cleanly as I'd expected. Dropping the
--dynamic flag, I do seem to get a '.a' file.
Offhand, I'm not certain whether this is a personal problem (mine), a
case of bitrot, or something that never worked as I thought it did.
We'll look into it further.
-Brad
On Wed, 11 Oct 2017, Russel Winder wrote:
Forgive that I may just have failed to do enough research:
Is there a way of compiling to a shared object with C linkage entry
points?
I am guessing the entry points are procs with export annotations, but
what
command line to generate a shared object.
--
Russel.
==========================================
Dr Russel Winder t: +44 20 7585 2200
41 Buckmaster Road m: +44 7770 465 077
London SW11 1EN, UK w: www.russel.org.uk
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users