zeromq / erlzmq

Erlang bindings for ZeroMQ messaging
Erlang ZeroMQ Bindings
Other
49 stars 15 forks source link

Error when loading library (Mac OS X) #5

Open dieu opened 14 years ago

dieu commented 14 years ago

zmq:start_link(). \ exception exit: {bad_return_value,"dlopen(/opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.so, 2): image not found"}

ls -al /opt/local/lib/erlang/lib/zmq-0.1/priv/ total 112 drwxr-xr-x 3 root wheel 102 22 сен 16:24 . drwxr-xr-x 9 root wheel 306 22 сен 16:06 .. -rwxr-xr-x 1 root wheel 54980 22 сен 16:06 zmq_drv.dylib

erlzmq and zeromq2 build master branch Erlang: R14A

dhammika commented 14 years ago

What's your erl version? Looks like it's looking for a .so! I don't have a Mac to test this, could you try renaming zmq_drv.dylib as zmq_drv.so?

dhammika commented 14 years ago

Here's erlang vm code, it's appending FILE_EXT to driver name and FILE_EXT is defined as ".so".

int erts_sys_ddll_open(char *full_name, void **handle)
{
#if defined(HAVE_DLOPEN)
    char dlname[MAX_NAME_LEN+1];
    int len;

    if ((len = sys_strlen(full_name)) >= MAX_NAME_LEN-EXT_LEN) {
    return ERL_DE_LOAD_ERROR_NAME_TO_LONG;
    }
    sys_strcpy(dlname, full_name);
    sys_strcpy(dlname+len, FILE_EXT);

    return erts_sys_ddll_open_noext(dlname, handle);
#else
    return ERL_DE_ERROR_NO_DDLL_FUNCTIONALITY;
#endif
}

Not sure why it's hardcoding .so extension.

dieu commented 14 years ago

I have a R14A version. Tried to rename, there is another error, but it still does not work.

dhammika commented 14 years ago

I don't have a mac to test this, what's the error? I'd google how mac dylibs are loaded, but it doesn't seem to be looking for dylibs at all.

dieu commented 14 years ago

zmq:start_link().
*\* exception exit: {bad_return_value,"dlopen(/opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.so, 2): no suitable image found.  Did find:\n\t/opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.so: mach-o, but wrong architecture"}
I can you help? This error appeared after merge branches and update version of Erlang.
dhammika commented 14 years ago

Just to make sure this is not a ppc/x86 issue, could you post the output of "file /opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.so"? But this is more likely to be a mac ports issue, following link explains how to build universal binaries, https://trac.macports.org/wiki/howto/buildUniversal You'd have to rebuild zmq and erlzmq again.

dieu commented 14 years ago

file /opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.dylib
/opt/local/lib/erlang/lib/zmq-0.1/priv/zmq_drv.dylib: Mach-O dynamically linked shared library i386

Ok, thx I'll look and try.

jrwest commented 13 years ago

Having the same problem on OS X 10.6.5. Erlang R14B (erts 5.8.1), zeromq/zeromq2 v2.1.0 tag and zeromq/erlzmq master as of 12/21/10. Has anyone found a workaround for this? From the comments above it seems Erlang defaults to .so and erlzmq builds a dylib. Is it possible to build erlzmq as a so instead? Renaming .dylib to .so did not work as mentioned in above comment. My current workaround is to install virtual box and do my erlang zmq stuff on linux but it OS X support would be nice.

dhammika commented 13 years ago

In configure.ac we set LIB_EXT, try changing it.

case "${host_os}" in         
    *darwin*)
    DARWIN_CXXFLAGS="-dynamiclib -Wl,-undefined -Wl,dynamic_lookup"
        CXXFLAGS="-D_DARWIN_C_SOURCE $DARWIN_CXXFLAGS $CXXFLAGS"
    AC_SUBST([LIB_EXT], [.dylib])
    ;;
    *)
    AC_SUBST([LIB_EXT], [.so]);;
esac

Please report your findings here, tnx.

jrwest commented 13 years ago

Changed the line AC_SUBST([LIB_EXT], [.dylib]) to AC_SUBST([LIB_EXT], [.so]). The .so built fine (got through make) but I now get the following when trying zmq:start_link().

1> zmq:start_link(). \ exception exit: {bad_return_value,"dlopen(/Users/jordanrw/Sandbox/erlang/erlzmq/priv/zmq_drv.so, 2): no suitable image found. Did find:\n\t/Users/jordanrw/Sandbox/erlang/erlzmq/priv/zmq_drv.so: mach-o, but wrong architecture"}

dhammika commented 13 years ago

Could be something to do with mac ports, can you post the output of following command? file /Users/jordanrw/Sandbox/erlang/erlzmq/priv/zmq_drv.so

jrwest commented 13 years ago

I'm actually using homebrew not macports but I can try installing from source if you would like.

Here is output of command: $ file /Users/jordanrw/Sandbox/erlang/erlzmq/priv/zmq_drv.so /Users/jordanrw/Sandbox/erlang/erlzmq/priv/zmq_drv.so: Mach-O dynamically linked shared library i386

I'm wondering if different DARWIN_CXXFLAGS need to be set but I'm no expert in the area.