Clang cannot finds standard system lib libssl.a

Eduardo Morras emorrasg at
Fri May 31 13:30:12 UTC 2013


I'm trying to compile a single big file project written in C. It compiled fine, without problems in my develop machine (FreeBSD 9.1 STABLE, Clang3.2) but not on the server (FreeBSD 9.1 Release#0, Clang 3.1). The app uses openssl dtls and links to system ssl libs. Am I missing something?

For compile I do:

%clang gog_server.c -o gog_server -v -I /usr/include/openssl

but I get a lot of undefined references to whole openssl lib functions, structs etc in Link phase:

gog_server.c:(.text+0x9): undefined reference to `CRYPTO_num_locks'
gog_server.c:(.text+0x50): undefined reference to `CRYPTO_num_locks'

I have manually checked that:

a) /usr/lib/libssl.a /usr/lib/ exist
b) The linker has /usr/lib path

    %clang -print-search-dirs 
    programs: =/usr/bin
    libraries: =/usr/bin/../lib/clang/3.1:/usr/lib

c) Add -Xlinker "-L /usr/lib"
d) Add -Xlinker "-l /usr/lib/libssl.a", get this from linker:

"/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ -o gog_server /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/gog_server-8bAHxn.o "-l /usr/lib/libssl.a" -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/usr/bin/ld: cannot find "-l /usr/lib/libssl.a"

e) Tried c) and d) without "", but get the same answers /usr/bin/ld: cannont find ...

Finally, this is the relevant output of last try:

% clang gog_server.c -o gog_server -v -I /usr/include/openssl -Xlinker /usr/lib/libssl.a 2>err

FreeBSD clang version 3.1 (branches/release_31 156863) 20120523
Target: x86_64-unknown-freebsd9.0
Thread model: posix
 "/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd9.0 -emit-obj -mrelax-all -disable-free -main-file-name gog_server.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.1 -I /usr/include/openssl -fmodule-cache-path /var/tmp/clang-module-cache -fdebug-compilation-dir /home/gowen/clang/Gog -ferror-limit 19 -fmessage-length 0 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=non-legacy -fdiagnostics-show-option -o /tmp/gog_server-mK51RB.o -x c gog_server.c
clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-unknown-freebsd9.0
ignoring nonexistent directory "/usr/bin/../lib/clang/3.1/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ -o gog_server /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/gog_server-mK51RB.o /usr/lib/libssl.a -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/tmp/gog_server-mK51RB.o: In function `THREAD_setup':
gog_server.c:(.text+0x9): undefined reference to `CRYPTO_num_locks'

and a lot of similar lines.

So, Am I missing something? 

Thanks in advance.

---   ---
Eduardo Morras <emorrasg at>

More information about the freebsd-questions mailing list