简体   繁体   中英

Compiling C with Python3.10 and OpenSSL-1.1: undefined symbol "OPENSSL_sk_num"

The configure script for nginx/unit fails because it is not able compile python extension code shown below:

#include <Python.h>

int main() {
  Py_Initialize();
  return 0;
}

I am using python3.10 which is compiled with openssl-1.1.1. The compilation gives several symbol not found error including "OPENSSL_sk_num". It seems the symbol is in libcrypto which I have linked in the compile command manually.

Do I need to compile Python again so as to statically link libcrypto and libssl in libpython.a? Below is the full compile command.

cc -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g -I/home/shared/Builds/Python-3.1
0.0/include/python3.10 -I/home/shared/Builds/Python-3.10.0/include/python3.10 -o build/autotest build/autotest.c -L/home/shared/Builds/Python-3.10.0/lib/python3.10/config-3.10 -L/home/shared/Buil
ds/Python-3.10.0/lib -lcrypto -lssl  -lpython3.10 -lpthread -lutil -lm -lm

Luckily, found the fix. Following works -- not sure why

cc -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g -I/home/shared/Builds/Python-3.10.0/include/python3.10 -I/home/shared/Builds/Python-3.10.0/include/python3.10 -o build/autotest build/autotest.c -L/home/shared/Builds/Python-3.10.0/lib/  -lpython3.10  -lpthread -lutil -lm  -L/usr/local/lib/eopenssl11 -lssl -lcrypto  

-lpython3.10 has to precede before -lssl which precedes -lcrypto .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM