ホームページ  >  記事  >  バックエンド開発  >  Ubuntu で Raspberry Pi 用にクロスコンパイルする方法: libstdc が見つからないのはなぜですか?

Ubuntu で Raspberry Pi 用にクロスコンパイルする方法: libstdc が見つからないのはなぜですか?

Barbara Streisand
Barbara Streisandオリジナル
2024-11-15 15:15:03222ブラウズ

How to Cross-Compile for Raspberry Pi on Ubuntu:  Why Can't I Find libstdc++?

How to Install a Cross-Compiler Toolchain on Your Host for the Raspberry Pi

Scenario:

You are attempting to cross-compile code for the Raspberry Pi on an Ubuntu machine. However, after installing the pre-built toolchain, you are encountering issues finding the libstdc++ shared library and utilizing the toolchain conveniently.

Solution:

To install and use the cross-compiler toolchain effectively, follow these steps:

Prerequisites:

Install the following prerequisites:

apt-get install git rsync cmake libc6-i386 lib32z1 lib32stdc++6

Setting Up the Toolchain:

  1. Create a folder named raspberrypi in your home directory:

    mkdir ~/raspberrypi
  2. Navigate to this folder and clone the toolchain repository:

    cd ~/raspberrypi
    git clone git://github.com/raspberrypi/tools.git

Integrating the Toolchain:

  1. Access the desired toolchain:

    export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
  2. Update your terminal or restart your session:

    • Log out and log back in.
    • Run . ~/.bashrc in your terminal to refresh your PATH.

Configuring CMake:

  1. Create a CMake configuration file (~/raspberrypi/pi.cmake):

    SET(CMAKE_SYSTEM_NAME Linux)
    SET(CMAKE_SYSTEM_VERSION 1)
    SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
    SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
    SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs)
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Creating a File System Mirror (Optional):

  1. Create a rootfs folder:

    mkdir ~/raspberrypi/rootfs
  2. Copy the /lib and /usr directories from your Raspberry Pi to ~/raspberrypi/rootfs:

    rsync -rl --delete-after --safe-links [email protected]:/{lib,usr} $HOME/raspberrypi/rootfs

Cross-Compiling with CMake:

To cross-compile using your configured toolchain, use the -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake flag with CMake.

Example:

Compile a simple "Hello World" program for the Raspberry Pi:

  1. Clone the "cmake-hello-world" repository:

    git clone https://github.com/jameskbride/cmake-hello-world.git 
  2. Create a build directory and navigate to it:

    cd cmake-hello-world
    mkdir build
    cd build
  3. Configure CMake using the toolchain file:

    cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../
  4. Build the program:

    make
  5. Transfer the executable to your Raspberry Pi:

    scp CMakeHelloWorld [email protected]:/home/pi/
  6. Run the program on your Raspberry Pi:

    ssh [email protected] ./CMakeHelloWorld

By following these steps, you will have successfully installed and integrated the Raspberry Pi cross-compiler toolchain, enabling you to conveniently cross-compile your applications.

以上がUbuntu で Raspberry Pi 用にクロスコンパイルする方法: libstdc が見つからないのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。