vs2017调试linux程序

2019-07-13 05:22发布



1.win10设置为开发人员模式,并安装subsystem for linux(命令行输入bash就可以安装)


2.登录并su到root,然后修改/etc/sudoers,在最后一行加(一定要在最后一行):
youname1     ALL=(ALL)  NOPASSWD:ALL


3.修改/etc/apt/sources.list,注释掉原来的源,添加:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
修改后apt-get update


4.安装相关开发软件
sudo apt install -y build-essential
sudo apt install -y gdbserver
sudo apt install -y openssh-server
修改/etc/ssh/sshd_config,把PasswordAuthentication改为yes
sudo ssh-keygen -A
sudo service ssh start          每次启动控制台都需要执行,因为控制台会关掉WSL的所有程序


5.修改ssh端口,默认的22被windows占用了
vi /etc/ssh/sshd_config


如果要使用vs2017调试linux程序,参考:
https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/