<div dir="ltr">Hi,<div><br></div><div style>This is my first try at ECL, and need help in figuring out what is missing. I had tried googling for similar examples but did not found one that demoed what i wanted.</div><div style>

<br></div><div style>I'm trying to define a function named sum-array in CL, which is defined in a file called foo.lisp</div><div style><br></div><div style>I compiled foo.lisp, generated foo.o, and then used that to create a shared library libtest.so</div>

<div style><br></div><div style>Finally I created a C file named try.c that will load libtest.so dynamically, which succeeded, but failed to locate the symbol L1sum_array or demo_sum_array.</div><div style><br></div><div style>

I double checked the files and the online resources (docs, and some online tutorials), but couldn't find a clue on what I was missing.</div><div style><br></div><div style>the files and the steps used to compile the example are attached below for reference.</div>

<div style><br></div><div style>Ala'a</div><div style><br></div><div style>----------------------------------------------------------------------</div><div style><br></div><div style><div>;; foo.lisp</div><div>(defpackage "DEMO"</div>

<div>  (:use :cl)</div><div>  (:export "SUM-ARRAY"))</div><div><br></div><div style>;; using the following</div><div><div>;;;(declaim (si::c-export-fname sum-arary))</div></div><div style>;; gave me</div><div>;;Unknown declaration specifier SI::C-EXPORT-FNAME</div>

<div style>;; so instead I tried 'proclaim', but it seem to have</div><div style>;; no effect as the generated symbol name is L1sum_array rather than demo_sum_array</div><div>(proclaim '(si::c-export-fname sum-arary))<br>

</div><div><br></div><div>(defun sum-array (array)</div><div>  (loop for i from 0 below (length array)</div><div>        summing (aref array i)))</div><div><br></div><div><div>----------------------------------------------------------------------</div>

</div><div><br></div><div><br></div><div style>; launch ECL in a console</div><div>; ecl -norc</div><div style>; then execute the following.</div><div>;> (compile-file "foo.lisp" :c-file t :h-file t :data-file t :system-p t)</div>

<div>;> (c:build-shared-library "test" :lisp-files '("foo.o"))</div><div><br></div><div><div>----------------------------------------------------------------------</div></div><div><br></div><div>

<div>// try.c</div><div>#include <stdlib.h></div><div>#include <stdio.h></div><div>#include <dlfcn.h></div><div><br></div><div>int main(char **argv, int argc) {</div><div>  void * libhandle;</div><div>  int (*demo_sum_array)(int[]);</div>

<div>  int nums[10] = {1, 2, 0, 0, 4, 5, 6, 9, 9, 17};</div><div><br></div><div>  // Load Shared library</div><div>  libhandle = dlopen("./libtest.so",RTLD_NOW);</div><div>  if(libhandle==NULL) {</div><div>    fprintf(stderr, "Couldn't open library: %s\n",</div>

<div><span class="" style="white-space:pre">    </span>    dlerror());</div><div>    exit(1);</div><div>  }</div><div><br></div><div>  // summ-array</div><div>  ////demo_sum_array  = dlsym(libhandle,"demo_sum_array");</div>

<div>  demo_sum_array  = dlsym(libhandle,"L1sum_array");</div><div>  if(demo_sum_array == NULL) {</div><div>    /* ERROR HANDLING */</div><div>    fprintf(stderr, "%s\n", dlerror());</div><div>    exit(1);</div>

<div>  }</div><div><br></div><div>  printf("Return is %i\n",(*demo_sum_array)(nums));</div><div><br></div><div>  dlclose(libhandle);</div><div><br></div><div>  return 0;</div><div><br></div><div>}</div><div><br>

</div><div><div>----------------------------------------------------------------------</div></div><div><br></div><div style>: gcc -g try.c -o try -L./ -ltest -ldl</div></div><div style><br></div><div style>: ./try <br></div>

<div style><div>./libtest.so: undefined symbol: L1sum_array</div><div><br></div></div></div></div>