Docker 容器中的交叉编译器 link

Cross compiler link in Docker container

为了使用 visual studio 2019 交叉编译程序,我在使用 docker 容器时遇到了一些麻烦。

这是我的 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

但是当我打开 shell 并输入

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"
        }
      ]
    }