简体   繁体   中英

Cross compiler link in Docker container

I have some troubles using a docker container in order to cross compile a program with visual studio 2019.

Here is my docker file

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}

Here is how a create my image

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

But when I open a shell and type

which g++ 
which gcc 

I have nothing. I've also tried to set the path manually

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

But it doesn't work.

I think my environnement is okay because I can cross compile a simple programm using a g++ from the packages (locate in /usr/bin/g++)

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

Thanks in advance.

Finally, I've changed my project in Visual Studio 2019 to a CMake project. I've created a CMake file in the shared volume of my container.

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)

And in Visual Studio 2019, I've changed the 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"
        }
      ]
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM