0

Setup:

Host:-- amd64 VM hosting Ubuntu Mate 15.10 with Eclipse Mars x64 installed. Also Linaro x64 toolchain installed

Target:-- armhf Ubuntu Mate 15.10 Raspberry Pi

Issue

I am trying to cross compile an existing code I found on git However I am unable to do so due to linker error. The project, has a compiled lib mqtt3as.so which looks for libcrypt and libssl. Those are not found by linker. I should mention that I tried below steps..

-- Git code builds fine on Raspberry Pi

-- Host to Target cross compiler works fine with Hello_world code. Deploy and Debug works

-- NFS mounted /lib and /usr/lib from Raspi to toolchainx64/lib folder

but nothing changes. I understand that the issue is related to linker unable to find the libraries. I have tried to follow all possible advice I googled. Below is log from eclipse on host. I can share verbose log if needed.

Literally run out of ideas now. I have unix experience ..but that was years ago and fairly new to eclipse. Still if need arise, I can learn and explore.


Log

    18:18:50 **** Build of configuration Default for project prj_c ****
make all 
Building file: ../cJSON.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"cJSON.d" -MT"cJSON.o" -o "cJSON.o" "../cJSON.c"
Finished building: ../cJSON.c

Building file: ../cpustat.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"cpustat.d" -MT"cpustat.o" -o "cpustat.o" "../cpustat.c"
../cpustat.c: In function ‘GetCPULoad’:
../cpustat.c:68:10: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration]
          sleep(1);
          ^
../cpustat.c:63:11: warning: unused variable ‘dump’ [-Wunused-variable]
      char dump[50];
           ^
Finished building: ../cpustat.c

Building file: ../iotmain.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"iotmain.d" -MT"iotmain.o" -o "iotmain.o" "../iotmain.c"
../iotmain.c: In function ‘main’:
../iotmain.c:75:6: warning: unused variable ‘lckStatus’ [-Wunused-variable]
  int lckStatus;
      ^
../iotmain.c: In function ‘trim’:
../iotmain.c:266:2: warning: implicit declaration of function ‘isspace’ [-Wimplicit-function-declaration]
  while (isspace(*(++frontp)))
  ^
../iotmain.c: In function ‘get_config’:
../iotmain.c:291:17: warning: unused variable ‘str2’ [-Wunused-variable]
  char str1[10], str2[10];
                 ^
../iotmain.c:291:7: warning: unused variable ‘str1’ [-Wunused-variable]
  char str1[10], str2[10];
       ^
Finished building: ../iotmain.c

Building file: ../jsonReader.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"jsonReader.d" -MT"jsonReader.o" -o "jsonReader.o" "../jsonReader.c"
Finished building: ../jsonReader.c

Building file: ../jsonator.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"jsonator.d" -MT"jsonator.o" -o "jsonator.o" "../jsonator.c"
Finished building: ../jsonator.c

Building file: ../mac.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"mac.d" -MT"mac.o" -o "mac.o" "../mac.c"
Finished building: ../mac.c

Building file: ../mqttPublisher.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c" -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"mqttPublisher.d" -MT"mqttPublisher.o" -o "mqttPublisher.o" "../mqttPublisher.c"
../mqttPublisher.c: In function ‘subscribeMessage’:
../mqttPublisher.c:117:6: warning: unused variable ‘i’ [-Wunused-variable]
  int i;
      ^
../mqttPublisher.c:126:10: warning: ‘command’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   sprintf(command,"sudo /sbin/shutdown -r %d", time_delay);
          ^
Finished building: ../mqttPublisher.c

Building target: prj_c
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L"/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib" -o "prj_c"  ./cJSON.o ./cpustat.o ./iotmain.o ./jsonReader.o ./jsonator.o ./mac.o ./mqttPublisher.o   -lpaho-mqtt3as
/home/k/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: warning: libcrypto.so.1.0.0, needed by /home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so, not found (try using -rpath or -rpath-link)
/home/k/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: warning: libssl.so.1.0.0, needed by /home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so, not found (try using -rpath or -rpath-link)
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_get_error@OPENSSL_1.0.0'
makefile:44: recipe for target 'prj_c' failed
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_load_verify_locations@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_alert_desc_string_long@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_msg_callback@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_get1_session@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_write@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `CRYPTO_THREADID_set_numeric@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `ERR_get_error@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_alert_type_string_long@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_default_passwd_cb@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CIPHER_get_name@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_load_error_strings@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_default_passwd_cb_userdata@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_new@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `CRYPTO_set_locking_callback@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `OPENSSL_add_all_algorithms_noconf@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_use_PrivateKey_file@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_library_init@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_get_current_cipher@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_cipher_list@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_default_verify_paths@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_shutdown@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_connect@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_get_cipher_list@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSLv23_client_method@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_use_certificate_chain_file@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `ERR_print_errors_fp@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_info_callback@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_set_session@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_new@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `CRYPTO_THREADID_set_callback@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `CRYPTO_num_locks@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_free@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_read@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSLeay_version@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `ERR_load_crypto_strings@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_get_verify_result@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_free@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_ctrl@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_pending@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_CTX_set_verify@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_state_string_long@OPENSSL_1.0.0'
/home/k/dev/workspace/iot/iot-raspberrypi/samples/c/lib/libpaho-mqtt3as.so: undefined reference to `SSL_set_fd@OPENSSL_1.0.0'
collect2: error: ld returned 1 exit status
make: *** [prj_c] Error 1

18:18:52 Build Finished (took 1s.675ms)
Manish
  • 1
  • 2

2 Answers2

0

You are missing 2 libraries on your build system: libcrypto.so.1.0.0 and libssl.so.1.0.0.

The developers added an extra section in their repository describing what is needed to build the samples: Note for users who want to change the code, compile and build the .deb file

One thing they state there is that you need to install libssl-dev which will automatically install libssl1.0.0. This package contains both libcrypto.so.1.0.0 and libssl.so.1.0.0.

So running sudo apt-get install libssl-dev might solve your problem.

BUT: You are not directly building the code on the arm system but on an x86/64 system. I am not sure that linking will work though.

Simon Kraemer
  • 5,700
  • 1
  • 19
  • 49
  • I did install libssl-dev on host as well as target. The code builds fine on Raspberry pi. And I NFS mounted lib folders to toolchain folder on host. I assumed this should solve the issue but it didn't. Looking at the log how should I interpret the long path where libcrypto.so.1.0.0 is not found. The path is in format ../../../../../..//bin/ld – Manish Mar 08 '16 at 13:56
  • That's just the path to the `ld` executable. Have you tried to add the folder to the library path [(link)](http://stackoverflow.com/questions/2726993/g-how-to-specify-preference-of-library-path)? – Simon Kraemer Mar 08 '16 at 14:02
  • arm..g++ -search-dirs gives many including following folders. /home/k/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../arm-linux-gnueabihf/libc/lib/ ......................... /home/k/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../arm-linux-gnueabihf/libc/usr/lib/ I mounted /lib and usr/lib to subfolders at these locations – Manish Mar 08 '16 at 14:09
  • @Manish This looks pretty similar to your problem: https://www.raspberrypi.org/forums/viewtopic.php?f=33&t=37658 – Simon Kraemer Mar 08 '16 at 14:17
  • Found this in verbose mode *********** GNU ld (crosstool-NG linaro-1.13.1) Supported emulations: armelf_linux_eabi armelfb_linux_eabi . using internal linker script: ===================== OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) SEARCH_DIR("=/usr/local/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/usr/lib"); ******** Are these the search dirs for linker? I thought g++ --search-dirs are search paths. – Manish Mar 08 '16 at 15:29
0

I was able to build correctly. Since beginning it was always linker path issue. However due to my lack of expertise with Eclipse and linux, I was not able to find the cause. Posting my observations for others.

  1. Linker was looking for libssl.so and libcrypto.so. Whereas the error in eclipse console was to look for libcrypto.1.0.0. Can someone guide me why this naming issue ?
  2. I was able to build using both local lib folder as well as NFS link to external libraries.
  3. The link to libraries -L should be to final folder of .so and not to parent or up in hierarchy.
  4. While using NFS , due to issue mentioned in point 1, I logged into the target (Raspberry Pi) and made link of .so.1.0.0 to .so via file explorer > right click > make link. This link was showing broken on host nfs mount. Maybe it was absolute. There were few standard libs with links which looked fine.
  5. For valid run from eclipse on host, if comes across error - "error while loading shared libraries" then those libraries need to be copied to /lib or /usr/lib on the target.
Manish
  • 1
  • 2