0

reposted from security.stackoverflow as this may be a more appropriate section for the question.

I am getting multiple undefined references when gcc attempts to link my code. I built openssl-3.0.5 using "./Configure --api=1.0.0 no-deprecated linux-x86_64" and I am linking against the static libraries libssl.a and libcrypto.a (using the -static flag to gcc). All of the EVP_MAC_xxx come up undefined (init, update, CTX_new, fetch, final) along with i2d_X509 and others.

I do not get any compiler errors or warnings, only the linker is having issues. When I type "nm -A libcrypto.a | grep EVP_MAC_update" I get

libcrypto.a:libcrypto-lib-mac_lib.o: 0000000000000420 T _EVP_MAC_update

libcrypto.a:libcrypto-lib-siv128.o: U _EVP_MAC_update

libcrypto.a:libdefault-lib-kbkdf.o: U _EVP_MAC_update

libcrypto.a:libdefault-lib-sskdf.o: U _EVP_MAC_update

libcrypto.a:libdefault-lib-tls1_prf.o: U _EVP_MAC_update

libcrypto.a:libdefault-lib-drbg_hmac.o: U _EVP_MAC_update

libcrypto.a:libdefault-lib-mac_legacy_sig.o: U _EVP_MAC_update

Any suggestions on what I can do to resolve this issue would be appreciated. I suspect that I am building openssl incorrectly.

The gcc options include the "-I" for the inlcude directories, the -Lopenssl-3.0.5, the "-static" so that gcc will pull the ".a" files instead of the ".so" files, and -lssl, -lcrypto, and -lrt sinc I am using mqueue.h. The code compiles with no errors or warnings. The gcc command is of the form "gcc -lrt -I. -Iopenssl-3.0.5/include -static -L./openssl-3.0.5 -lssl -lcrypto file.c" The errors that I am seeing from gcc are:

/tmp/ccy9kLz0.o: In function `file_await_pull_response_state':

file.c:(.text+0x5da): undefined reference to `EVP_MAC_fetch'

file.c:(.text+0x5ea): undefined reference to `EVP_MAC_CTX_new'

file.c:(.text+0x6cd): undefined reference to `EVP_MAC_init'

file.c:(.text+0x6ec): undefined reference to `EVP_MAC_update'

tstone
  • 31
  • 4
  • 2
    Please show the exact linker command instead of the description. – 273K Aug 10 '22 at 07:03
  • Not as a duplicate proposal (I would hammer....) but does this help: https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix Please refer to the details and explain why they are not applicable or not helpful in your case. (Sorry. tagged c++, anybody has a C sibling link?) – Yunnosch Aug 10 '22 at 07:05
  • Original question edited to show gcc command and some of the actual errors. Also, I tried with -lrt at the beginning as shown and at the end right before the "file.c" and the mq_open and mq_send show up as undefined references also. I have another file that uses the mqueue.h and mq_open and mq_send compiled with "gcc -I. -lrt file.c" and that produces an a.out with no errors or warnings. – tstone Aug 10 '22 at 12:26

1 Answers1

0

It appears the the -lssl, -lcrypto, and -lrt need to be placed at the end of the gcc command, after the filename of the file to build. Had to add -ldl also to get rid of additional undefined references that popped up in the openssl files.

tstone
  • 31
  • 4