Erlang interoperability
在HTML文档的doc/tutorial下有文件(新添Makefile):
inter |-- Makefile |-- cnode_c.c |-- cnode_s.c |-- cnode_s2.c |-- complex.c |-- complex1.erl |-- complex2.erl |-- complex3.erl |-- complex4.erl |-- complex5.erl |-- ei.c |-- erl_comm.c |-- port.c `-- port_driver.c
CFLAGS=-I/usr/local/lib/erlang/lib/erl_interface-3.6.4/include -I/usr/local/lib/erlang/erts-5.7.4/include LDFLAGS=-L/usr/local/lib/erlang/lib/erl_interface-3.6.4/lib APPS=cserver cserver2 cclient ext_ei ext_port example_drv.so all: $(APPS) cserver: complex.o cnode_s.o gcc $(LDFLAGS) $^ -lerl_interface -lei -lpthread -o $@ cserver2: complex.o cnode_s2.o gcc $(LDFLAGS) $^ -lerl_interface -lei -lpthread -o $@ cclient: complex.o cnode_c.o gcc $(LDFLAGS) $^ -lerl_interface -lei -lpthread -o $@ ext_port: complex.o erl_comm.o port.o gcc $(LDFLAGS) $^ -lerl_interface -lei -lpthread -o $@ ext_ei: complex.o erl_comm.o ei.o gcc $(LDFLAGS) $^ -lerl_interface -lei -lpthread -o $@ example_drv.so: complex.o port_driver.o gcc -o $@ -fpic -shared $^ %.o : %.c gcc -c $(CFLAGS) $^ clean: rm -rf *.beam rm -rf *.o rm -rf $(APPS)
ProgrammingErlang(JoeArmstrong)随书的代码有误,编译的.so无法加载:
ErlDrvEntry example_driver_entry = { NULL, /* F_PTR init, N/A */ example_drv_start, /* L_PTR start, called when port is opened */ example_drv_stop, /* F_PTR stop, called when port is closed */ example_drv_output, /* F_PTR output, called when erlang has sent data to the port */ NULL, /* F_PTR ready_input, called when input descriptor ready to read*/ NULL, /* F_PTR ready_output, called when output descriptor ready to write */ "example1_drv", /* char *driver_name, the argument to open_port */ NULL, /* F_PTR finish, called when unloaded */ NULL, /* F_PTR control, port_command callback */ NULL, /* F_PTR timeout, reserved */ NULL /* F_PTR outputv, reserved */ }; DRIVER_INIT(example1_drv) /* must match name in driver_entry */ { return &example_driver_entry; }
DRIVER_INIT(example1_drv)/*mustmatchnameindriver_entry*/
带的erl_driver.h删除,用系统的。
相关推荐
chenpro 2020-08-09
NVEFLY 2020-07-04
liym 2020-06-21
OnMyHeart 2020-06-06
天空windy 2020-06-03
87447007 2020-05-16
OnMyHeart 2020-05-09
NVEFLY 2020-04-17
M守护神 2020-03-28
大史哥哥 2020-03-07
wbingyang 2020-02-27
liym 2020-02-22
zhoucheng0 2020-02-19
wbingyang 2020-02-14
OnMyHeart 2020-01-14
OnMyHeart 2020-01-08
大史哥哥 2019-12-31
wbingyang 2019-12-31