Eu tenho a fonte de um aplicativo escrito em Qt/C++ que posso tentar construir no Linux.
O sistema é Ubuntu 19.04. O aplicativo requer algumas versões mais antigas do pacote, por exemplo, openssl-1.0.2.
Executei as seguintes etapas após a instalação para configurar o Qt 5.11:
sudo su -
apt-get install build-essential
apt-get install qtcreator
apt-get install qt5-default
apt-get install git
apt-get install qtwebengine5-dev
apt-get install qtmultimedia5-dev
apt-get install qtscript5-dev
apt-get install open-vm-tools-desktop
cd /opt
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
gunzip openssl-1.0.2l.tar.gz
tar xf openssl-1.0.2l.tar
cd openssl-1.0.2l/
./config
make install
ln -s /opt/openssl-1.0.2l/include/openssl/ /usr/include/openssl
apt install libleptonica-dev
apt-get install tesseract-ocr
apt-get install libtesseract-dev
apt-get install libvlc-dev
Após os passos acima, a aplicação compila em Qt, mas a construção deu o ld
erro:
Não foi possível encontrar a libssl Não foi possível encontrar a libcrypto
Acho que isso ocorre porque essas bibliotecas existem como .a
bibliotecas vinculadas estáticas, não como bibliotecas de objetos compartilhados .so.
Eu tentei construir o .so
seguinte:
cd /opt/openssl-1.0.2l
./config shared
make install
Isso falha com:
make[2]: Entering directory '/opt/openssl-1.0.2l'
[ -z "" ] || gcc -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -Iinclude \
-DFINGERPRINT_PREMAIN_DSO_LOAD -o fips_premain_dso \
fips_premain.c fipscanister.o \
libcrypto.a -ldl
make[3]: Entering directory '/opt/openssl-1.0.2l'
make[4]: Entering directory '/opt/openssl-1.0.2l'
/usr/bin/ld: libcrypto.a(gost_eng.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile.shared:169: link_a.gnu] Error 1
make[4]: Leaving directory '/opt/openssl-1.0.2l'
make[3]: *** [Makefile:357: do_linux-shared] Error 2
make[3]: Leaving directory '/opt/openssl-1.0.2l'
make[2]: *** [Makefile:310: libcrypto.so.1.0.0] Error 2
make[2]: Leaving directory '/opt/openssl-1.0.2l'
make[1]: *** [Makefile:109: shared] Error 2
make[1]: Leaving directory '/opt/openssl-1.0.2l/crypto'
make: *** [Makefile:287: build_crypto] Error 1
Portanto, a questão é: como fazer com que o openssl-1.0.2 produza libssl.so e libcrypt.so no Ubuntu 19.04.
Responder1
O ./config --shared
comando é adicionado -fPIC
ao Makefile CFLAGS
, o que faz com que qualquer arquivo C seja compilado em um formato adequado para vinculação a uma biblioteca compartilhada.
No entanto, quaisquer arquivos que já tenham sido compilados em código-objeto ( .o
arquivos) durante a construção estática padrão não terão o arquivo CFLAGS
. A tentativa de vincular esses arquivos a uma biblioteca compartilhada falhará.
A solução é executar make clean
para excluir todos os .o
arquivos antes de executar make install
a nova configuração da biblioteca compartilhada.