为Raspbian交叉编译cpp-netlib时出错

时间:2014-01-14 12:19:37

标签: cmake raspberry-pi cross-compiling raspbian cpp-netlib

我已经使用交叉编译器成功编译了boost(使用了Installing Raspberry Pi Cross-Compiler中的指令)并且它工作得很好。

我将lib和include移动到rootfs中,以便cmake找到它...当我运行cmake时,我得到了

gervasio@ubuntu:~/cpp-netlib-0.10.1$ cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.55.0
-- Found the following Boost libraries:
--   unit_test_framework
--   system
--   regex
--   date_time
--   thread
--   filesystem
--   program_options
--   chrono
-- Found OpenSSL: /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so;/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so (found version "1..1")
-- Looking for include files CMAKE_HAVE_PTHREAD_H
-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gervasio/cpp-netlib-0.10.1

这太棒了......现在,当我运行make时,它以

结束
gervasio@ubuntu:~/cpp-netlib-0.10.1$ make

...

[ 15%] Building CXX object libs/network/test/CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o
cd /home/gervasio/cpp-netlib-0.10.1/libs/network/test && /home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++   -DBOOST_NETWORK_ENABLE_HTTPS -Wall -I/home/gervasio/raspberrypi/rootfs/usr/include -I/home/gervasio/cpp-netlib-0.10.1    -Wall -o CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o -c /home/gervasio/cpp-netlib-0.10.1/libs/network/test/message_test.cpp
Linking CXX executable ../../../tests/cpp-netlib-message_test
cd /home/gervasio/cpp-netlib-0.10.1/libs/network/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/cpp-netlib-message_test.dir/link.txt --verbose=1
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++    -Wall    CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o  -o ../../../tests/cpp-netlib-message_test -rdynamic /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_unit_test_framework.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_system.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_regex.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_date_time.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_thread.a -lpthread /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_filesystem.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_program_options.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_chrono.a -lpthread ../src/libcppnetlib-uri.a /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so -lrt -Wl,-rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf 
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so, not found (try using -rpath or -rpath-link)
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflateInit_'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflate'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `deflateEnd'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflate'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflateInit_'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `inflateEnd'
/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so: undefined reference to `zError'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/cpp-netlib-message_test] Error 1
make[2]: Leaving directory `/home/gervasio/cpp-netlib-0.10.1'
make[1]: *** [libs/network/test/CMakeFiles/cpp-netlib-message_test.dir/all] Error 2
make[1]: Leaving directory `/home/gervasio/cpp-netlib-0.10.1'
make: *** [all] Error 2

但......在〜/ raspberrypi / rootfs / lib / arm-linux-gnueabihf里面有一个libz.so.1

gervasio@ubuntu:~/raspberrypi/rootfs/lib/arm-linux-gnueabihf$ ls -lah libz.so*
lrwxrwxrwx 1 gervasio gervasio  13 Jun 24  2012 libz.so.1 -> libz.so.1.2.7
-rw-r--r-- 1 gervasio gervasio 86K Jun 24  2012 libz.so.1.2.7

我知道它在测试中失败了,我可以使用这些库...但我真的希望有一个良好的环境来交叉编译我需要的任何东西。

感谢您的帮助:)

编辑刚刚在树莓上运行了ldd libssl.so并获得了

/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6ec6000)
libcrypto.so.1.0.0 => /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0 (0xb6d57000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6d4c000)
libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xb6d2e000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6bff000)
/lib/ld-linux-armhf.so.3 (0xb6f24000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6bd7000)

编辑2:如果我使用-DCMAKE_SKIP_BUILD_RPATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE -DCMAKE_INSTALL_RPATH=/home/gervasio/raspberrypi/rootfs/lib/arm-linux-gnueabihf -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE运行cmake,我会得到此输出

/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++    -Wall    CMakeFiles/cpp-netlib-message_test.dir/message_test.cpp.o  -o ../../../tests/cpp-netlib-message_test -rdynamic /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_unit_test_framework.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_system.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_regex.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_date_time.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_thread.a -lpthread /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_filesystem.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_program_options.a /home/gervasio/raspberrypi/rootfs/usr/lib/libboost_chrono.a -lpthread ../src/libcppnetlib-uri.a /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libcrypto.so -lrt -Wl,-rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf 
/home/gervasio/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libssl.so, not found (try using -rpath or -rpath-link)

它说-rpath,/home/gervasio/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf似乎没问题,对吧?

1 个答案:

答案 0 :(得分:2)

感谢@ruslo和他发布的链接,我想出来了...这是告诉cmake使用rpath的方法

cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake -DCMAKE_SKIP_BUILD_RPATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE -DCMAKE_INSTALL_RPATH=/home/gervasio/raspberrypi/rootfs/lib/arm-linux-gnueabihf -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE .