users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using C++ with the gplc compiler


From: Fergus Henderson
Subject: Re: Using C++ with the gplc compiler
Date: Tue, 20 Feb 2001 19:08:14 +1100

On 19-Feb-2001, Jay Bradley <address@hidden> wrote:
> threeBody.o: threeBody.cc
>       gplc -v --c-compiler g++ -c threeBody.cc -o threeBody.o -C 
> -I/usr/local/gprolog-1.2.1/include/

> threeBody.o: In function `main':
> threeBody.o(.text+0xb5): undefined reference to `Start_Prolog(int, char **)'
> threeBody.o(.text+0xc5): undefined reference to `Find_Atom(char *)'
> threeBody.o(.text+0xe2): undefined reference to `Pl_Query_Start(int, int, 
> long 
> *, int)'
> threeBody.o(.text+0xf6): undefined reference to `Pl_Query_End(int)'
> threeBody.o(.text+0xfe): undefined reference to `Reset_Prolog(void)'
> threeBody.o(.text+0x10d): undefined reference to `Stop_Prolog(void)'

The reason that you're getting those undefined symbols is probably that
(1) You #included a C header file into a C++ source file
(2) You didn't wrap the `#include' inside `extern "C" { ... }'
(3) The C++ compiler therefore thought that these functions where C++
    functions, and thus mangled their names to include the argument
    types
(4) The functions that you're linking with were compiled with a C
    compiler, which did not mangle their names.
(5) Thus the linker complains, because the mangled names are not
    defined in the library.

The best fix is probably to address step (2), i.e. change

        #include "foo.h"

to

        extern "C" {
        #include "foo.h"
        }

-- 
Fergus Henderson <address@hidden>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]