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)


Programming Erlang(Joe Armstrong)随书的代码有误,编译的.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;
}


[color=red]DRIVER_INIT(example1_drv) /* must match name in driver_entry */[/color]
[color=red]带的erl_driver.h删除,用系统的。[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值