[erlang-questions] Problems with C Erlang interface

Jachym Holecek jachym.holecek@REDACTED
Wed Jan 30 14:09:12 CET 2008


On Wed, 30 Jan 2008 13:09:43 +0100, J Bhanot <j.bhanot@REDACTED> wrote:
> [root@REDACTED otp_src_R12B-0]# cc -o test
> -I/usr/local/lib/erlang/lib/erl_interface-3.5.5.3/include
> -L/usr/local/lib/erlang/lib/erl_interface-3.5.5.3/lib -lerl_interface  
> -lei
> test.c
>
> got the following error -
>
> /tmp/ccAvr8jd.o: In function `main':
> test.c:(.text+0x28): undefined reference to `erl_init'
> collect2: ld returned 1 exit status
> [root@REDACTED otp_src_R12B-0]#

To quote gcc(1):

   [explanation of '-l' option]
   It makes a difference where in the command you write this option; the  
linker searches and processes
   libraries and object files in the order they are specified.  Thus, foo.o  
-lz bar.o searches library
   z after file foo.o but before bar.o.  If bar.o refers to functions in z,  
those functions may not be
   loaded.

So you might try to put the arguments in different order:

   [root@REDACTED otp_src_R12B-0]# cc -o test \
   -I/usr/local/lib/erlang/lib/erl_interface-3.5.5.3/include \
   -L/usr/local/lib/erlang/lib/erl_interface-3.5.5.3/lib \
   test.c \
   -lerl_interface \
   -lei

(FWIW the 'erl_init' symbol is defined in liberl_interface.a)

> Also, i tried
>
> [root@REDACTED otp_src_R12B-0]# ld
> -L/usr/local/lib/erlang/lib/erl_interface-3.5.5.3/lib test.o
> -lerl_interface -lei -lpthread -o test

Using ld(1) requires you to know exactly what you're doing. Normally,
you want to let [g]cc(1) compile & link your program (it will invoke ld(1)
internally with the correct options).

HTH,
     -- Jachym




More information about the erlang-questions mailing list