user465001
user465001

Reputation: 846

Cannot find which file represents the library you need to link

I have built and install code to my directory /usr/local/lib:

ls /usr/local/lib:

drwxr-xr-x 2 root root      4096 Apr  9 13:04 LibreSSL
drwxr-xr-x 3 root root      4096 Mar 20 09:54 netscape
drwxr-xr-x 2 root root      4096 Apr  9 20:06 pkgconfig
drwxrwsr-x 4 root staff     4096 Dec 28 21:56 python2.7
drwxrwsr-x 3 root staff     4096 Oct 17 09:24 python3.7
-rw-r--r-- 1 root root  21403926 Apr  8 18:05 libcrypto.a
-rwxr-xr-x 1 root root       969 Apr  8 18:05 libcrypto.la
lrwxrwxrwx 1 root root        19 Apr  8 18:05 libcrypto.so -> libcrypto.so.46.0.1
lrwxrwxrwx 1 root root        19 Apr  8 18:05 libcrypto.so.46 -> libcrypto.so.46.0.1
-rwxr-xr-x 1 root root  10741400 Apr  8 18:05 libcrypto.so.46.0.1
-rw-r--r-- 1 root root   4714494 Apr  8 18:05 libssl.a
-rwxr-xr-x 1 root root       976 Apr  8 18:05 libssl.la
lrwxrwxrwx 1 root root        16 Apr  8 18:05 libssl.so -> libssl.so.48.0.1
lrwxrwxrwx 1 root root        16 Apr  8 18:05 libssl.so.48 -> libssl.so.48.0.1
-rwxr-xr-x 1 root root   2219448 Apr  8 18:05 libssl.so.48.0.1
-rw-r--r-- 1 root root    870622 Apr  8 18:05 libtls.a
-rwxr-xr-x 1 root root      1001 Apr  8 18:05 libtls.la
lrwxrwxrwx 1 root root        16 Apr  8 18:05 libtls.so -> libtls.so.20.0.1
lrwxrwxrwx 1 root root        16 Apr  8 18:05 libtls.so.20 -> libtls.so.20.0.1
-rwxr-xr-x 1 root root    433640 Apr  8 18:05 libtls.so.20.0.1
-rwxr-xr-x 1 root root       958 Apr  9 20:06 libwolfssl.la
lrwxrwxrwx 1 root root        20 Apr  9 20:06 libwolfssl.so -> libwolfssl.so.24.0.0
lrwxrwxrwx 1 root root        20 Apr  9 20:06 libwolfssl.so.24 -> libwolfssl.so.24.0.0
-rwxr-xr-x 1 root root    473280 Apr  9 20:06 libwolfssl.so.24.0.0

I want to use hmac.h from wolfssl. However, when I run gcc -L/usr/local/lib -o my_hmac_test my_hmac_test.c -lwolfssl the code builds with a warning that address later:

In file included from /usr/local/include/wolfssl/wolfcrypt/types.h:29,
                 from /usr/local/include/wolfssl/wolfcrypt/hash.h:29,
                 from /usr/local/include/wolfssl/wolfcrypt/hmac.h:31,
                 from my_hmac_test.c:1:
/usr/local/include/wolfssl/wolfcrypt/settings.h:2053:14: warning: #warning "For timing resistance / side-channel attack prevention consider using harden options" [-Wcpp]
 2053 |             #warning "For timing resistance / side-channel attack prevention consider using harden options"
      |              ^~~~~~~

However, when I run the code. I get this error:

./my_hmac_test: error while loading shared libraries: libwolfssl.so.24: cannot open shared object file: No such file or directory

How can I fix this?

strace -f -e open gcc -L/usr/local/lib -o my_hmac_test my_hmac_test.c -lwolfssl:

strace: Process 32629 attached
In file included from /usr/local/include/wolfssl/wolfcrypt/types.h:29,
                 from /usr/local/include/wolfssl/wolfcrypt/hash.h:29,
                 from /usr/local/include/wolfssl/wolfcrypt/hmac.h:31,
                 from my_hmac_test.c:1:
/usr/local/include/wolfssl/wolfcrypt/settings.h:2053:14: warning: #warning "For timing resistance / side-channel attack prevention consider using harden options" [-Wcpp]
 2053 |             #warning "For timing resistance / side-channel attack prevention consider using harden options"
      |              ^~~~~~~
[pid 32629] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32629, si_uid=1000, si_status=0, si_utime=2, si_stime=1} ---
strace: Process 32630 attached
[pid 32630] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32630, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 32631 attached
strace: Process 32632 attached
[pid 32632] +++ exited with 0 +++
[pid 32631] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=32632, si_uid=1000, si_status=0, si_utime=1, si_stime=1} ---
[pid 32631] +++ exited with 0 +++
--- SIGCHLD {si_signo=SI

Upvotes: 0

Views: 313

Answers (2)

Mike Kinghan
Mike Kinghan

Reputation: 61147

The compiler warning you have observed is unrelated to the runtime loader failure.

I have built and install code to my directory /usr/local/lib

After you have placed any new shared library in any of the linker's default search directories you must run:

ldconfig

as root, to update the OS loader's database of system libraries. Otherwise, at runtime, the loader will remain unaware of the new library. You haven't actually finished installing the new library until you have done this. If you don't do it, then you will be obliged to use the LD_LIBRARY_PATH hack that you discovered.

See man ldconfig

Upvotes: 1

user465001
user465001

Reputation: 846

Entered into my terminal export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib and ran gcc -L/usr/local/lib -o my_hmac_test my_hmac_test.c -lwolfssl from that same terminal. I should add the export line to my .bashrc now.

Upvotes: 1

Related Questions