[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Apr 1 17:14:57 2002 
Subject:Re: external C call 
From:Aaron Sloman See text for reply address 
Volume-ID:1020401.02 

[To reply replace "Aaron.Sloman.XX" with "A.Sloman"]

mhl@Cs.Nott.AC.UK writes:

> Date: Mon, 1 Apr 2002 16:30:22 +0000 (UTC)
 
> Here's the c function I'm using to test...  (It's in a file called test.cc)
>
> int foo(int x)
> {
>   int y;
>   y=x+1;
>   return y;
> }
>
> The poplog file I have is...
>
> exload test [libtest]
> foo(x) :int
> endexload;
>
>
> I compile the test.cc file into a shared object library with the following commands...
>
> g++ -c -fpic test.cc
> g++ -shared -o libtest.so test.o

You have used the Gnu C++ compiler, not the C compiler which is gcc.
The man gcc file on my linux machine states:

       gcc    assumes preprocessed (.i) files are C and assumes C
              style linking.

       g++    assumes preprocessed (.i) files are C++ and assumes
              C++ style linking.


       Suffixes of source file names indicate  the  language  and
       kind of processing to be done:

       .c    C source; preprocess, compile, assemble
       .C    C++ source; preprocess, compile, assemble
       .cc   C++ source; preprocess, compile, assemble
       .cxx  C++ source; preprocess, compile, assemble

So you should use .c as the file suffix if you intend the program to
compiled and linked as if it were a C program.

>
> When I try to compile the poplog exload it complains
>
> ;;; Error: can't find value for symbol foo
>
> ;;; MISHAP - ERRORS ACCESSING EXTERNAL SYMBOLS (see above)
> ;;; FILE     :  /home/mhl/external/temp.p   LINE NUMBER:  3
> ;;; DOING    :  external_do_load exload runproc
>
> I checked the symbols is the library and there's a 'foo_Fi'
> ...so I changed the poplog code to read...
>
> exload test [libtest]
> foo(x) :int <-'foo_Fi'
> endexload;
>
> which works fine. I noticed a section on symbol names in
> ref * external (line 856) which says that exload should automatically do the mapping.

That assumes that you are using C, not C++


Try again after re-naming your file test.c

    gcc -c -fpic test.c
    gcc -shared -o libtest.so test.o


    exload test [libtest]
        (language C)
        foo(x) :int
    endexload;

    exacc foo(33) =>
    ** 44

(I never use C. I have just copied stuff from examples in REF EXTERNAL)

I hope that helps.

There are many examples of external function calls in the Pop-11 X
libraries in here:

    $usepop/pop/x/pop/*/*.p

Aaron
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk   (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html