I’m trying to compile and run my code on a raspberry pi which needs the snmp libraries. However, I get linking errors such as “undefined reference to ‘EVP_DigestUpdate'”.
I’ve been researching this issue for the past few days and found out that this usually happens when snmp can’t find the ssl library crypto, for example if you don’t specify -lcrypto before -lsnmp when linking your object, or when the linker just can’t can’t find -lcrypto.
However, on my raspberry pi I have all required libraries in /usr/lib/gcc/arm-linux-gnueabihf.
This is how I installed the libraries:
apt-get install libssl-dev libsnmp-dev libsnmp-base libsnmp30
I generate trap.o with this command:
gcc -c -g -pedantic -Wall -Wshadow -I/home/pi/tests/h -I/usr/include trap.c -o trap.o
I link trap.o the libraries with this command:
gcc -static -g -pedantic -Wall -Wshadow trap.o -o trap -L/usr/lib/arm-linux-gnueabihf/lib -lcrypto -lpthread -lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp
And then I get this error:
gcc -static -g -pedantic -Wall -Wshadow trap.o -o trap -L/usr/lib/arm-linux-gnueabihf/lib -lcrypto -lpthread -lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_gid': (.text+0x1144): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_gid': (.text+0x1154): warning: Using 'endgrent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_uid': (.text+0x10d8): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_uid': (.text+0x10e8): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_getaddrinfo': (.text+0x4a4): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_gethostbyaddr': (.text+0x9f8): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking trap.o: In function `parse_address': /home/pi/tests/trap.c:56: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o: In function `_start': /build/glibc-6f8a9a/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to `main' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_random': (.text+0x168): undefined reference to `RAND_bytes' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash': (.text+0x290): undefined reference to `EVP_md5' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash': (.text+0x2b4): undefined reference to `HMAC' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash': (.text+0x33c): undefined reference to `EVP_sha1' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x424): undefined reference to `EVP_sha1' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x42c): undefined reference to `EVP_MD_CTX_create' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x438): undefined reference to `EVP_DigestInit' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x448): undefined reference to `EVP_DigestUpdate' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x458): undefined reference to `EVP_DigestFinal' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x468): undefined reference to `EVP_MD_CTX_destroy' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash': (.text+0x488): undefined reference to `EVP_md5' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0x86c): undefined reference to `DES_key_sched' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0x8a0): undefined reference to `DES_ncbc_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0x8c4): undefined reference to `DES_ncbc_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0x90c): undefined reference to `AES_set_encrypt_key' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0x948): undefined reference to `AES_cfb128_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0xa74): undefined reference to `DES_key_sched' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt': (.text+0xaac): undefined reference to `DES_ncbc_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt': (.text+0xc78): undefined reference to `AES_set_encrypt_key' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt': (.text+0xcb0): undefined reference to `AES_cfb128_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt': (.text+0xd9c): undefined reference to `DES_key_sched' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt': (.text+0xdd0): undefined reference to `DES_cbc_encrypt' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x74): undefined reference to `EVP_MD_CTX_create' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x98): undefined reference to `EVP_md5' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0xa4): undefined reference to `EVP_DigestInit' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0xe8): undefined reference to `EVP_DigestUpdate' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x10c): undefined reference to `EVP_DigestFinal' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x138): undefined reference to `EVP_MD_CTX_destroy' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x178): undefined reference to `EVP_sha1' /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku': (.text+0x184): undefined reference to `EVP_DigestInit' collect2: error: ld returned 1 exit status
Could it be that the issue is being caused because the snmp libraries I installed were built using a different openssl version than the ones I have in my environment? My libssl-dev and libsnmp-dev versions are the following:
dpkg -l | grep libssl-dev:
ii libssl-dev:armhf 1.0.1k-3+deb8u5 armhf Secure Sockets Layer toolkit - development files
dpkg -l | grep libsnmp-dev:
ii libsnmp-dev 5.7.2.1+dfsg-1 armhf SNMP (Simple Network Management Protocol) development files
Any help would be appreciated,
Thanks
Advertisement
Answer
All of your undefined references are in libnetsnmp
and they are all undefined
references to functions defined in libcypto
. This happens because -lcrypto
precedes -lnetsnmp
in your linkage.
In the linkage sequence, files that need symbol definitions must occur
before the ones that provide the definitions, because the linker by default will
only search a library to find definitions of symbols that it has
observed to be referenced, but not defined, in earlier files. (You appear to
have mis-learned this rule, the wrong way round). From man ld
:
The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.
So link -lcrypto
after -lnetsnmp
.