[erlang-questions] creating linked in drivers for Erlang on OSX using gcc
Tim Watson
watson.timothy@REDACTED
Sun Mar 16 00:47:00 CET 2008
Hi all,
I'm writing a linked in driver for Erlang/OTP12B. I've got it all
working on Windows but having problems getting things to work on Mac
OS. On the dev machine in question (a Mac Air), I can compile my code
but can't link it with erts properly. When linking, the erl_driver API
isn't being linked properly:
air:/Volumes/Shore/Aidem/Apps/erlxsl/erlxsl3/c_src io2$ gcc -g -Wall
-DDEBUG -dynamiclib -o ../priv/bin/erlxsl.dylib -fPIC
../priv/obj/driver.a ../priv/obj/protocol.a
-L/usr/local/lib/erlang/usr/lib -L/usr/local/lib/erlang/erts-5.6.1/bin
-L/usr/local/lib/erlang/erts-5.6.1/lib -L/usr/local/lib/erlang/bin
-L/usr/local/lib/erlang/lib -L../priv/bin -L/usr/local/lib/ -Wl,-rpath
/usr/local/lib/ -Wl,-rpath /usr/local/lib/erlang/bin -Wl,-rpath
/usr/local/lib/erlang/lib -Wl,-rpath /usr/local/lib/erlang/usr/lib
-lsablot -lxslprovider -dynamic
Undefined symbols:
"_driver_send_term", referenced from:
_sendResponse in protocol.a
_sendResponse in protocol.a
"_driver_alloc", referenced from:
_start_driver in driver.a
"_driver_caller", referenced from:
_output in driver.a
"_driver_mk_atom", referenced from:
_sendResponse in protocol.a
"_driver_async", referenced from:
_output in driver.a
"_driver_free", referenced from:
_stop_driver in driver.a
"_driver_mk_port", referenced from:
_sendResponse in protocol.a
"_driver_failure_atom", referenced from:
_output in driver.a
_output in driver.a
_output in driver.a
_sendResponse in protocol.a
ld: symbol(s) not found
collect2: ld returned 1 exit status
To get around this, I've supplied an option to gcc that tells the
linker not to worry about missing symbols (option -undefined
dynamic_lookup) and I can link the compiled object files to get a
shared library. I skip undefined symbols to get it to link like this:
air:/Volumes/Shore/Aidem/Apps/erlxsl/erlxsl3/c_src io2$ gcc -g -Wall
-DDEBUG -dynamiclib -undefined dynamic_lookup -o
../priv/bin/erlxsl.dylib -fPIC ../priv/obj/driver.a
../priv/obj/protocol.a -L/usr/local/lib/erlang/usr/lib
-L/usr/local/lib/erlang/erts-5.6.1/bin
-L/usr/local/lib/erlang/erts-5.6.1/lib -L/usr/local/lib/erlang/bin
-L/usr/local/lib/erlang/lib -L../priv/bin -L/usr/local/lib/ -Wl,-rpath
/usr/local/lib/ -Wl,-rpath /usr/local/lib/erlang/bin -Wl,-rpath
/usr/local/lib/erlang/lib -Wl,-rpath /usr/local/lib/erlang/usr/lib
-lsablot -lxslprovider -dynamic
Now linking works, so I rush into the shell to see if the driver
works. No joy - I get an error message that appears to indicate I've
either compiled the object files in the wrong format or linked
incorrectly:
air:/Volumes/Shore/Aidem/Apps/erlxsl/erlxsl3 io2$ erl -pa ./priv/bin/ -pz ./ebin
Erlang (BEAM) emulator version 5.6.1 [source] [smp:2]
[async-threads:0] [kernel-poll:false]
Eshell V5.6.1 (abort with ^G)
1> Driver = "erlxsl", erl_ddll:load("./priv/bin", Driver).
{error,{open_error,-12}}
2> erl_ddll:load("./priv/bin", Driver).
{error,{open_error,-12}}
3> Error = erl_ddll:load("./priv/bin", Driver).
{error,{open_error,-12}}
4> Error.
{error,{open_error,-12}}
5> erl_ddll:format_error(Error).
** exception error: bad argument
in function erl_ddll:format_error_int/1
called as erl_ddll:format_error_int({error,{open_error,-12}})
in call from erl_ddll:format_error/1
6> erl_ddll:format_error({open_error,-12}).
"Driver is an inappropriate Mach-O file"
7> q().
ok
8>
Yes, I do realize that load/2 is a deprecated function. The error
message coming back from format_error/1 seems to indicate that the
file format is incorrect. I'm hardly a Mac expert, so I'm a little
lost with this error message. I've peeked into the *ld* man pages and
found a few things that look worthy of investigation, but if anyone
here can see an obvious problem I'd really appreciate the help.
Also, can anyone tell me why I'm having to set -undefined
-dynamic_lookup and why gcc isn't picking up the erl_driver API from
the shared libs in %OTP_TOP%/usr/lib? I don't have this problem at all
on Windows (haven't tried it on Linux yet) and can't see why the
linker isn't picking up these symbols properly. :(
More information about the erlang-questions
mailing list