xhs / librtcdc

Tiny portable WebRTC Data Channel in C.
Other
247 stars 39 forks source link

Undefined reference/symbol after compiling #19

Open DurandA opened 7 years ago

DurandA commented 7 years ago

After compiling librtcdc.so using CFLAGS="-std=gnu11" make using gcc-4.8 (copied to /usr/lib/librtcdc.so) and pyrtcdc.so using sh compile.sh, I get _undefined symbol: nice_candidatefree when I try the python example.

This is probably due to my own incompetence in build systems. I tried adding -Wl,--no-undefined after CFLAGS in the Makefile but I'm getting a bunch of undefined references to various libraries:

dtls.c:100: undefined reference to `SSL_library_init'
dtls.c:101: undefined reference to `OPENSSL_add_all_algorithms_noconf'
dtls.c:103: undefined reference to `DTLSv1_method'
...
dtls.o: In function `gen_key':
dtls.c:20: undefined reference to `EVP_PKEY_new'
dtls.c:21: undefined reference to `BN_new'
dtls.c:22: undefined reference to `RSA_new'
...

Do you compile with the vanilla Makefile? What am I missing there?

xhs commented 7 years ago

Hi @DurandA , this is how to do it manually:

Install latest openssl, libnice and usrsctp, you can find them here:

Make sure pkg-config works well. If not, add $OPENSSL_INSTALLED_DIR/lib/pkgconfig and $LIBNICE_INSTALLED_DIR/lib/pkgconfig to PKG_CONFIG_PATH.

$ PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libnice/lib/pkgconfig pkg-config --cflags openssl nice
-D_REENTRANT -I/usr/local/Cellar/openssl/1.0.2j/include -I/usr/local/opt/libnice/include/nice -I/usr/local/opt/libnice/0.1.13/include -I/usr/local/Cellar/glib/2.48.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.48.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.39/include
$ PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libnice/lib/pkgconfig pkg-config --libs openssl nice
-L/usr/local/Cellar/openssl/1.0.2j/lib -L/usr/local/opt/libnice/lib -L/usr/local/Cellar/glib/2.48.2/lib -L/usr/local/opt/gettext/lib -lssl -lcrypto -lnice -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl 

If usrsctp is installed in /usr/local and you get errors like these,

./sctp.h:12:10: fatal error: 'usrsctp.h' file not found

and

ld: library not found for -lusrsctp

specify CPATH and LIBRARY_PATH:

CPATH=/usr/local/include
LIBRARY_PATH=/usr/local/lib

Run make in src:

PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libnice/lib/pkgconfig CPATH=/usr/local/include LIBRARY_PATH=/usr/local/lib make

Make sure librtcdc[.so|.dylib] and its dependences can be found in LD_LIBRARY_PATH.

Use otool or ldd to check that:

otool -L librtcdc.dylib 
librtcdc.dylib:
    librtcdc.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/opt/libnice/lib/libnice.10.dylib (compatibility version 15.0.0, current version 15.1.0)
    /usr/local/opt/glib/lib/libgthread-2.0.0.dylib (compatibility version 4801.0.0, current version 4801.2.0)
    /usr/local/opt/glib/lib/libgio-2.0.0.dylib (compatibility version 4801.0.0, current version 4801.2.0)
    /usr/local/opt/glib/lib/libgobject-2.0.0.dylib (compatibility version 4801.0.0, current version 4801.2.0)
    /usr/local/opt/glib/lib/libglib-2.0.0.dylib (compatibility version 4801.0.0, current version 4801.2.0)
    /usr/local/opt/gettext/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
    /usr/local/lib/libusrsctp.1.dylib (compatibility version 2.0.0, current version 2.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)

or

ldd -r librtcdc.so

Good luck. 😃