Hi.
I am writing an external feature function for cdec based on the example given in 'example_extff'.
However, while testing my code not only on OSX but also on our Unix servers I came across the following issue:
While linking the example dynamic library into cdec ( this is done by dlopen(lib, RTLD_LAZY) in ff_external.cc ) under OSX works perfectly, I received the following error at runtime under Unix:
>>> ./cdec -c cdec.ini
cdec v1.0 (c) 2009-2011 by Chris Dyer
Configuration file: cdec.ini
feature: External (with config parameters '/cdec/example_extff/.libs/libff_example.so')
dlopen reports: /cdec/example_extff/.libs/libff_example.so: undefined symbol: _ZN15FeatureFunction15PrepareForInputERK16SentenceMetadata
Did you provide a full path to the dynamic library?
Aborted
It seems that the main executable (cdec) is not compiled with the "-rdynamic" flag for the linker.
Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of dlopen or to allow obtaining backtraces from within a program.
I was able to resolve this issue in two ways: Either by adding a "cdec_LDFLAGS = -rdynamic" to 'cdec/decoder/Makefile.am' or by running the build with "./configure LDFLAGS='-rdynamic'".
I am by no means experienced in using autotools or writing dynamic libraries, but I wanted to share this in case someone else runs into this problem. I hope this issue isn't too obvious to mention it.
Maybe a small note in 'example_extff/README.md' would be helpful.
best regards,
Felix
P.S. some info I came across while searching for answers:
http://old.nabble.com/dlopen()-returns-undefined-symbol-for-library-w--RTLD_LAZY-td24621028.html
http://www.informit.com/articles/article.aspx?p=22435
http://swig.10945.n7.nabble.com/Re-dlopen-works-for-C-binary-but-not-Perl-or-Python-SWIG-td464.html