Tag Archives: Cambrian

[Solved] error adding symbols: File in wrong format collect2: error: ld returned 1 exit status

Mqtt is required in a project CPP, compile mqtt on the Cambrian box cpp。 mqtt. CPP is dependent on mqtt C library and header files, I first compiled mqtt c. Then compile mqtt During CPP, use the following cmake command to specify mqtt C library and header file location

cmake -DPAHO_WITH_SSL=OFF -DPAHO_MQTT_C_LIBRARIES=/home/chw/mqtt/paho.mqtt.c-master/install/lib64/libpaho-mqtt3a.so  -DPAHO_MQTT_C_INCLUDE_DIRS=/home/chw/mqtt/paho.mqtt.c-master/install/include/ DCMAKE_INSTALL_PREFIX=../install ..

Then the following errors are reported during compilation

/home/chw/mqtt/paho.mqtt.c-master/install/lib64/libpaho-mqtt3a.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
src/CMakeFiles/paho-mqttpp3.dir/build.make:99: recipe for target 'src/libpaho-mqttpp3.so.1.2.0' failed
make[2]: *** [src/libpaho-mqttpp3.so.1.2.0] Error 1
CMakeFiles/Makefile2:89: recipe for target 'src/CMakeFiles/paho-mqttpp3.dir/all' failed
make[1]: *** [src/CMakeFiles/paho-mqttpp3.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

The first reaction to this error is that the format of the library linked by the LD command of arm is x86, so the prompt file in wrong format

Then I went to mqtt Under the install folder of C, use the file command to see the format of the library,

root@localhost:/home/chw/mqtt/paho.mqtt.c-master/install/lib64# file libpaho-mqtt3a.so.1.3.9
libpaho-mqtt3a.so.1.3.9: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

You can see that the format of this library is x86-64, and our Cambrian box is ARM architecture, so the format is not recognized. At this time, I suddenly found out how to mqtt There are lib and lib64 folders in the install folder of C, so I go to the Lib folder and use the file command to see the format.

root@localhost:/home/chw/mqtt/paho.mqtt.c-master/install/lib# file libpaho-mqtt3a.so.1.3.9
libpaho-mqtt3a.so.1.3.9: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=1875ae7550029980d276187e883c154aa43c7356, not stripped

I was pleasantly surprised to find that the Library under the Lib folder was in arm aarch64 format, so the cause of the problem was found. I used the Library under the lib64 folder when configuring cmake, so I used mqtt when configuring cmake The library path of C can be changed to Lib folder.

cmake -DPAHO_WITH_SSL=OFF -DPAHO_MQTT_C_LIBRARIES=/home/chw/mqtt/paho.mqtt.c-master/install/lib/libpaho-mqtt3a.so  -DPAHO_MQTT_C_INCLUDE_DIRS=/home/chw/mqtt/paho.mqtt.c-master/install/include/ DCMAKE_INSTALL_PREFIX=../install ..

Also: compile mqtt.com below During the CPP library, it was found that the compiled library was also x86. Later, it was found that the reason was that I directly compiled mqtt on X86 The CPP # project was copied and then re cmake. I didn’t download the source code from GitHub again. After cmake, the compiled CPP library is in aarch64 format.

Problem solved!