1

I need to use erl_interface in my C-program. There is Erlang R15B01 on Debian Wheezy.

I just do the following (for example).

// main.c
#include <ei.h>
#include <erl_interface.h>

int main() {
    erl_init(NULL,0);
    return 0;
}

Then i say:

cc -I/usr/lib/erlang/lib/erl_interface-3.7.7/include -L/usr/lib/erlang/lib/erl_interface-3.7.7/ -lei -lerl_interface -o prog main.c

Directory specified as -L contains libei.a and liberl_interface.a but linker abusing that reference to erl_init is undefined: undefined reference to erl_init

What may be wrong? Sorry for really stupid question.

Viacheslav Kovalev
  • 1,745
  • 12
  • 17
  • I suspect your -L path is wrong. check exactly where those libraries resides. it should have been "-L/usr/lib/erlang/lib/erl_interface-3.7.7/lib" – Icarus3 Jan 06 '13 at 19:16
  • Yes, of course, I try to build this specifying "-L/usr/lib/erlang/lib/erl_interface-3.7.7/lib". I've just misspelled, when writing my question. libei.a and liberl_interface.a realy resides here. And more - linker see this files but can not find function definitions. – Viacheslav Kovalev Jan 06 '13 at 19:34
  • try switching the order of libraries. i.e. -lerl_interface -lei – Icarus3 Jan 06 '13 at 19:57
  • Thanks! This not takes any effect. But I found that is not erl_interface trouble. Seems it trouble with my `ld` - it can't link no one other static library, abusing `undefined reference`. – Viacheslav Kovalev Jan 06 '13 at 20:04
  • only thing remains is platform compatibility. I am hoping that your static libraries are compiled for your platform. Otherwise linker would not bother to link. – Icarus3 Jan 06 '13 at 20:08
  • @ViacheslavKovalev What if you add `-lei -lerl_interface` to the **very end of the command line?** Like `gcc -o prog -I -L main.c -lei -lerl_interface`... –  Jan 06 '13 at 20:16
  • Yeah!!! Thanks a lot! `cc -o prog -I -L main.c -lei -lerl_interface` spit out abouth hundreed `undefined references`, but when I swap -lei and -lerl_interface to `cc -o prog -I -L main.c -lerl_interface -lei`, it was successfully linked. Well, think I need to read mans about gcc more attentively. – Viacheslav Kovalev Jan 06 '13 at 20:33
  • How can I close this question? (I am newbie here) – Viacheslav Kovalev Jan 06 '13 at 20:35
  • @ViacheslavKovalev I'm adding an answer, and you can accept it. –  Jan 06 '13 at 20:44

1 Answers1

2

Newest versions of the GNU toolchain require that the object files and libraries be specified in the same order their symbols depend on each other. So you should generally put the library flags to the end of the invocation, like this:

gcc -o prog main.c -L<libdir> -I<includedir> -lerl_interface -lei