Re: Cannot link from gcc 3.x.x, using gplc object

"Marcello Azambuja" <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
On Sun, Oct 19, 2008 at 10:40 PM, Idomeneo <[email protected]> wrote:

> Hello,
>
> I'm trying to compile and linking the example main_new (in folder
> ExamplesC, in gprolog folder) from my gcc 3.4.6 (instead than gplc [1.3.0],
> likewise the book taught) and I cannot do that!
>
> That's how I'm trying:
>
> - Create two object files with:
>
> $> gcc -c -o new_main_c.c -I ../src/EnginePl
> $> gplc -c new_main.pl
>
> ( with option "-I", I'm simply telling to gcc where to find gprolog.h)
>
> - Linking them together with gcc with:
>
> $>   gcc -o new_main new_main.o new_main_c.o -lbips_fd -lbips_pl
> -lengine_pl -lengine_fd -llinedit -L ../src/EnginePl -L ../src/BipsPl -L
> ../src/BipsFD -L ../src/EngineFD -L ../src/Linedit/
>
> (with "-L" options I tell to the gcc where to find libraries)
>
> It seems pretty clear (almost to me) but it doesn't work at all and I
> absolutely can't figure out why!!
> Below you can see output of what I get when I try to compile like I write
> above:
>
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Round':
> arith_inl_c.c:(.text+0x75a): undefined reference to `lrint'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Floor':
> arith_inl_c.c:(.text+0x7ba): undefined reference to `floor'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Ceiling':
> arith_inl_c.c:(.text+0x83a): undefined reference to `ceil'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Atan':
> arith_inl_c.c:(.text+0x1553): undefined reference to `atan'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Sqrt':
> arith_inl_c.c:(.text+0x15d9): undefined reference to `sqrt'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Pow':
> arith_inl_c.c:(.text+0x166c): undefined reference to `pow'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Log':
> arith_inl_c.c:(.text+0x16e3): undefined reference to `log'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Exp':
> arith_inl_c.c:(.text+0x1743): undefined reference to `exp'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Asin':
> arith_inl_c.c:(.text+0x17a3): undefined reference to `asin'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Sin':
> arith_inl_c.c:(.text+0x1803): undefined reference to `sin'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Acos':
> arith_inl_c.c:(.text+0x1863): undefined reference to `acos'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(arith_inl_c.o):
> In function `Fct_Cos':
> arith_inl_c.c:(.text+0x18c3): undefined reference to `cos'
> /usr/local/bin/../lib/gcc/i686-pc-linux-gnu/3.4.5/../../../libbips_pl.a(os_interf_c.o):
> In function `Select_5':
> os_interf_c.c:(.text+0x43e): undefined reference to `fmod'
> collect2: ld returned 1 exit status
>
> I don't know what to try or do, any advice or help would be nice; I really
> need to get rid of this!
> Thank you really much!
>
> Idomeneo
>

Looks like you forgot to link with '-lm', try adding it to your command
line:

gcc -o new_main new_main.o new_main_c.o -lm -lbips_fd -lbips_pl -lengine_pl
-lengine_fd -llinedit -L ../src/EnginePl -L ../src/BipsPl -L ../src/BipsFD
-L ../src/EngineFD -L ../src/Linedit/

That should solve the undefined references to math lib.

-- 
Marcello Azambuja

_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.