簡體   English   中英

Docker 容器中的交叉編譯器鏈接

[英]Cross compiler link in Docker container

我在使用 docker 容器時遇到了一些麻煩,以便與 Visual Studio 2019 交叉編譯程序。

這是我的 docker 文件

FROM ubuntu:16.04

RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -sf /bin/true /sbin/initctl
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get -y upgrade

# install 32 bit libraries required for gnuarm tools from
# https://launchpad.net/gcc-arm-embedded & a few minimalistic tools with ssh server
RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get -y install \
    libc6:i386 libncurses5:i386 libstdc++6:i386 libpython2.7:i386 vim \
    make git unzip \
    sudo curl less tree openssh-server

# clean cache
RUN apt-get clean

RUN mkdir -p /var/run/sshd

COPY *.tgz /tmp/
RUN cd /tmp && \
    tar zxvf gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf_5.3_sub1.0.3.tgz -C /opt && \
    tar zxvf Compiler_gcc-linaro-5.3_patch_1.2.2.tgz && \
    cd Compiler_gcc-linaro-5.3_patch && \
    bash ./install-owa4x-comp-PATCH-1.2.2.sh && \
    cd / && \ 
    rm -rf /tmp/*
ENV PATH="${PATH}:/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin"

RUN useradd -G sudo --create-home --shell /bin/bash --user-group myuser

RUN echo "myuser:myuser_pwd" | chpasswd

RUN echo "PATH=$PATH:/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linuxgnueabihf/bin" >> /etc/profile
CMD ["source /etc/profile"]

CMD ["/usr/sbin/sshd", "-D"]
EXPOSE 22

ENV WORKSPACE /home/myuser/workspace
VOLUME ${WORKSPACE}

這是創建我的圖像的方法

docker build --tag cc_arm .
myuser@ubuntu:~/Documents/share$ docker run -d -p 5000:22 -v /home/myuser/Documents/share:/home/myuser/workspace cc_arm

但是當我打開一個外殼並輸入時

which g++ 
which gcc 

我一無所有。 我也試過手動設置路徑

export C="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
export CXX="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++"

echo 'export CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc' >> ~/.bashrc
echo 'export CXX=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++' >> ~/.bashrc

但它不起作用。

我認為我的環境還可以,因為我可以使用包中的 g++ 交叉編譯一個簡單的程序(位於 /usr/bin/g++ 中)

 sudo apt install -y openssh-server build-essential gdb rsync ninja-build zip

提前致謝。

最后,我將 Visual Studio 2019 中的項目更改為 CMake 項目。 我在容器的共享卷中創建了一個 CMake 文件。

SET(CMAKE_C_COMPILER    /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER  /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_STRIP /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip)

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)

在 Visual Studio 2019 中,我更改了 launch.vs.json

"configurations": [
    {
      "type": "cppgdb",
      "name": "CMakeProject6 (CMakeProject6\\CMakeProject6)",
      "project": "CMakeLists.txt",
      "projectTarget": "CMakeProject6 (CMakeProject6\\CMakeProject6)",
      "debuggerConfiguration": "gdb",
      "args": [],
      "env": {},
      "remoteMachineName": "10.0.0.1 (username=root, port=22, authentication=Password)",
      "deploy": [
        {
          "sourceMachine": "192.168.72.144 (username=root, port=5000, authentication=Password)", // DOCKER CONTAINER
          "targetMachine": "10.0.0.1 (username=root, port=22, authentication=Password)", // REMOTE MACHINE
          "deploymentType": "RemoteRemote"
        }
      ]
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM