0

I'm trying to build the static libraries of Eclipse Paho MQTT C on a Raspberry Pi 3 B+. As a prerequisite it is necessary to have the static version of the OpenSSL library on the system.

First, I attempted to get it using the following commands:

git clone git://git.openssl.org/openssl.git
cd openssl
git checkout OpenSSL_1_1_1a
./config -static
sudo make install

This does produce a libssl.a File in /usr/local/lib. However, when I then try to build the static libraries of Paho using the following commands, it fails with the error below:

git clone https://github.com/eclipse/paho.mqtt.c.git
mkdir /tmp/build.paho
cd /tmp/build.paho
cmake -GNinja -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_STATIC=TRUE ~/paho.mqtt.c
ninja

enter image description here

/usr/bin/ld: /usr/local/lib/libssl.a(methods.o): relocation R_ARM_MOVW_ABS_NC against ‘a local symbol’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libssl.a: error adding symbols: Bad value

The suggested solution to this problem in several Stackoverflow questions seems to be to build the static OpenSSL library with the shared flag: ./config shared -static But even then, building of the static Paho libraries fails with the exact same error.

I should add that I did not have any troubles with this procedure on other hardware architectures. Could this problem be related to the Raspberry Pi in any way? How do I solve it?

ci7i2en4
  • 834
  • 1
  • 13
  • 27
  • Please, do not post and image with error message. Instead, post the error message as **text**. Among the other reasons, it is a rule of Stack Overflow. See [ask]. – Tsyvarev Nov 04 '19 at 10:25
  • Sorry, error added as text. – ci7i2en4 Nov 04 '19 at 12:15
  • "Standard" problem about `recompile with -fPIC`. You need OpenSSL to be compiled with that option. See e.g. [this answer](https://stackoverflow.com/a/19022607/3440745) about the possible way for doing this. – Tsyvarev Nov 04 '19 at 12:23
  • Did you try adding another defintion `-DCMAKE_POSITION_INDEPENDENT_CODE=ON` to your `cmake` command to enable PIC for all targets? (Suggested [here](https://stackoverflow.com/a/38297422/3987854)) – Kevin Nov 04 '19 at 17:03

1 Answers1

0

CFLAGS=-fPIC ./config shared -static seems to have worked for OpenSSL. However, after building the static Paho MQTT C libraries, which finishes without any errors, there are no static libraries to be found anywhere.

If I then look in /usr/local/lib, I only find the dynamic .o libraries there, no static .a ones. Why is this not working on the Pi but worked perfectly fine on a different system?

ci7i2en4
  • 834
  • 1
  • 13
  • 27