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!
Read More:
- VSCode Error: collect2.exe: error: ld returned 1 exit status
- GCC Error:(.text+0x24): undefined reference to `main‘collect2: error: ld returned 1 exit status [Solved]
- [Solved] VScode Error: undefined reference to ‘WinMain’ collect2.exe: error: ld returned 1 exit status
- Ubutnu Qt Unable to start process Error: “make“ -f ‘ /usr/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit sta
- VSCode Error: collect2.exe:error:1d returned 1 exit status [How to Solve]
- Dev C++ Error: error: ld returned 1 exit status [How to Solve]
- [Solved] VsCode + gfortran Compiler Error: error: ld returned 1 exit status
- DevC++ Error: [Error] Id returned 1 exit status [How to Solve]
- [Solved] QT error: //usr/local/lib/libvtkCommonCore-9.1.so.1: error adding symbols: DSO missing from command
- docker load Error processing tar file(exit status 1): archive/tar: invalid tar header
- Linux: tar Unpack .tar.bz2 File Error tar: Child returned status 2 tar: Error is not recoverable: exiting now
- NVM use error: exit status [How to Solve]
- TypeError: unsupported format string passed to numpy.ndarray.__format__
- vscode: Error loading workspace: err: exit status 1: stderr: build flag -mod=readonly only valid
- Solution of adding H264 error in ffmpeg compilation
- [Solved] ROS fatal error: alsa/asoundlib. h: There is no such directory or file
- [Solved] error getting credentials – err: exit status GDBus.Error:org.freedesktop.DBus.Error.ServiceU
- [Solved] fatal: not in a git directory Error: Command failed with exit 128: git
- [Solved] C++ Error: Undefined symbols for architecture x86_64: