docker 环境 本人已将配置好的 Docker 配置上传到了 docker hub,可以直接 pull。
1 docker pull rlyown/cdev_host
Dockerfile cdev_host >folded 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 FROM ubuntu:20.04 ENV LANG=en_US.UTF-8 ENV TZ=Asia/ShanghaiWORKDIR / ADD cgdb-0.7.1.tar.gz . RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \ && echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list \ && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list \ && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list \ && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \ && apt-get update -y \ && apt-get -y install gcc \ gcc-multilib \ g++ \ gdb \ nasm \ automake \ autoconf \ libtool \ make \ cmake \ ssh \ ntp \ vim \ wget \ curl \ telnet \ sudo \ git \ subversion \ doxygen \ lighttpd \ net-tools \ inetutils-ping \ python \ golang \ libbz2-dev \ libdb++-dev \ libssl-dev \ libdb-dev \ libssl-dev \ openssl \ libreadline-dev \ libcurl4-openssl-dev \ libncurses-dev \ autotools-dev \ build-essential \ libicu-dev \ python-dev \ libgmp-dev \ libmpfr-dev \ libmpc-dev \ grub2 \ libgcc-9-dev \ xorriso \ texinfo \ bison \ flex \ rsync \ && apt clean \ && mkdir /var/run/sshd \ && echo "Port 36000" >> /etc/ssh/sshd_config \ && echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config \ && mkdir /home/bingo \ && useradd -s /bin/bash bingo \ && echo "bingo:123456" | chpasswd \ && chown -R bingo:bingo /home/bingo \ && echo "bingo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \ && sed -ri 's/RSYNC_ENABLE=false/RSYNC_ENABLE=true/g' /etc/default/rsync WORKDIR /cgdb-0.7.1/ RUN ./autogen.sh \ && ./configure \ && make -srj4 \ && make install WORKDIR / RUN rm -rf cgdb-0.7.1 EXPOSE 36000 CMD ["/usr/sbin/sshd" , "-D" ]
docker-compose.yml 因为已经使用了本地端口映射的方式,因此不对网络进行配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 version: "2.2" services: dev_host: container_name: dev_host image: rlyown/cdev_host security_opt: - seccomp:unconfined - apparmor:unconfined ports: - 36000 :36000 - 1234 :1234 volumes: - .:/home/bingo/Workdir privileged: true
辅助脚本 编写一个脚本来处理这些命令。
1 2 3 4 5 6 7 8 9 10 11 #!/usr/bin/env bash action=$1 if [ "$action " = "enter" ]; then docker exec -it dev_host /bin/bash elif [ "$action " = "up" ]; then docker-compose -f docker-compose.yml up -d elif [ "$action " = "down" ]; then docker-compose down fi
CLion 配置 在 CLion 的设置中,选择Build, Execution, Deployment
中的Toolchains
。
Credential 的配置如下(cdev_host 账户 bingo 对应的密码为123456
):
然后修改CMake
,新增一个配置并将Toolchain
选项配置为刚刚创建好的cdev-host-remote
。
最后修改Deployment
,连接的配置不用怎么修改。主要修改的是Mappings
和Excluded Paths
。
Mapping
将本地的项目目录映射到远程主机的目录。
如果使用的是 Docker 的 mount 方式,即通过 Volume 方式共享文件夹的话,则不需要通过网络同步。所以将项目目录添加到Excluded Paths
中。
问题 如果上述修改完之后出现了头文件找不到的情况,那么点击工具栏的Tools
下的Resync with Remote Hosts
选项,重新同步项目即可解决。(clion-and-remote-headers )