Re: Prolog & C linking Problem

ppuchec_at_yahoo.com
Date: 01/19/04


Date: 19 Jan 2004 09:24:10 -0800

Jan Wielemaker <jan@ct.xs4all.nl> wrote in message news:<slrnc0ncgk.ms0.jan@ct.xs4all.nl>...
> In article <ab1c184b.0401190123.7f9deffb@posting.google.com>,
> ppuchec@yahoo.com wrote:
> > Hi all,
> >
> > I am trying to compile and link a Prolog source code being called by a
> > C Program.
> > My problem is:
> > I am trying to compile Prolog and C using plld.
> > At the linking process I get the messages "undefined reference to
> > `PL_new_term_ref'" and so...
> >
> > I am using swi-prolog 5.2.11 and Open Watcom 1.2 C
> > compiler in Windows 2000.
>
> plld is designed for MSVC (on Windows). Appearently you are not
> linking to libpl.lib, the export library of libpl.dll, something that
> should be done automatically by plld. Maybe plld gives the wrong
> options for the watcom compiler. Try plld -v <other options you gave>
> to see what it is doing. If all is right it should try to compile the
> C-bits and link the result together with the standard libraries and
> libpl.lib. After that it will attach the Prolog code, but that part
> should be C-compiler independent.
>
> Please report your findings (still problems, a fix, etc) to the
> Bugzilla system at http://gollem.swi.psy.uva.nl/bugzilla/
>
> Cheers --- Jan

Dear Jan,
Then, if plld is designed for MSVC, why it is not specified in the SWI
documentation? I thought that plld was prepared to work with a gnu
compliant c compiler and linker.
Any way, please, have a look to the details of the process:

** FILES IN DIRECTORY: **********************************
calc.c
calc.pl
libpl.lib (the file is also located in the swi path dir)
libpl.dll (the file is also located in the swi path dir)

** COMMAND TO EXECUTE: **********************************
plld calc.c calc.pl -v

** BEGIN RESULT: ****************************************
H:\pl\Pruebas\calc>plld calc.c calc.pl -v
        eval `plcon.exe -dump-runtime-variables`
                CC="cl"
                PLBASE="c:/programs/pl/swi"
                PLARCH="i386-win32"
                PLLIBS=""
                PLLIB="libpl.lib"
                PLLDFLAGS=""
                PLSOEXT="dll"
                PLTHREADS="yes"
        cl -c -D_REENTRANT /MD /DWIN32 /nologo -DWIN32 -D_WINDOWS
-D__SWI_PROLOG
__ -D__SWI_EMBEDDED__ -Ic:/programs/pl/swi/include -o calc.obj calc.c
Open Watcom C/C++ CL Clone for 386 Version 1.2
Portions Copyright (c) 1995-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Warning: Ignoring invalid option 'o'
calc.c
        LIB=c:\programs\pl\swi\lib;C:\SQL10\LIB
        link.exe /out:plout.exe /nologo calc.obj libpl.lib
Error! E2028: PL_initialise_ is an undefined reference
Error! E2028: PL_halt_ is an undefined reference
Error! E2028: PL_predicate_ is an undefined reference
Error! E2028: PL_new_term_refs_ is an undefined reference
Error! E2028: PL_put_atom_chars_ is an undefined reference
Error! E2028: PL_call_predicate_ is an undefined reference
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol
PL_initialise_
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol PL_halt_
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol
PL_predicate_
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol
PL_new_term_refs_
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol
PL_put_atom_chars_
file calc.obj(H:\pl\Pruebas\calc\calc.c): undefined symbol
PL_call_predicate_
        plcon.exe -f none -F none -g true -t
"consult(['calc.pl']),qsave_program
('pltmp-1608.exe',[goal='\$welcome',toplevel=prolog,initfile=none])"
% calc.pl compiled 0.01 sec, 2,424 bytes
% halt
        copy /b plout.exe+pltmp-1608.exe plout.exe
Could not open plout.exe: No such file or directory
        rm calc.obj
        rm pltmp-1608.exe
*** plld exit status 1

H:\pl\Pruebas\calc>

** END RESULT: ****************************************

As you can see, the linker is finding the libpl.lib file but is unable
to locate the symbols.
I have tried other compilers (i.e. digital mars) but the result is the
same.
I have also tried to pass other options to the linker, for example,
"-force:undefined", but in this case, the "plout.exe" file is created
but do nothing.

Thanks a lot
Pedro Puche
ppuchec@yahoo.com



Relevant Pages

  • Re: tcc - how do I specify the library paths ?
    ... There are a working "Makefile" that shows how to compile the samples. ... > tcc: undefined symbol 'arg_str0' ... >: undefined reference to `arg_lit0' ...
    (comp.os.linux)
  • Re: Problems linking MEXed object files.
    ... I added the .lib files to the list in my mexopts .bat file ... mxGetNumberOfElements_ is an undefined reference ...
    (comp.soft-sys.matlab)
  • How can I compile PF without option PFIL_HOOKS defined in the kernel conf file?
    ... kernel conf file to try to get PF compile into the kernel, ... PF failed to compile; ... : undefined reference to `pfil_head_get' ... Will this fix the problem? ...
    (comp.unix.bsd.openbsd.misc)
  • gprof
    ... I'm trying to compile my C application with gprof but it is not working. ... This is a multithreaded program that use mysql and openssl libraries. ... /lib/libcrypto.so.4: undefined reference to `sysconf' ...
    (freebsd-questions)
  • Re: gprof
    ... I'm trying to compile my C application with gprof but it is not working.. ... This is a multithreaded program that use mysql and openssl libraries. ... /lib/libcrypto.so.4: undefined reference to `sysconf' ...
    (freebsd-questions)