使用RDP、XDCMP连接ubuntu server,并安装vscode调试C++代码

主要有两种连接方式,一种用Windows自带的rdp协议,另外一种用xdmcp协议,下面说的是将不带界面的ubuntu server安装上界面,并且使用windows远程界面连接

1、使用windows下的RDP协议

apt-get install xrdp
apt-get install vnc4server
apt-get install xubuntu-desktop(如果安装ubuntu-desktop的话,可能还需要一个xfce)
xsession中写入xfce4-session,需要远程的用户都要单独执行这条命令:
         echo "xfce4-session" >~/.xsession
重启:
/etc/init.d/xrdp  restart

连接工具选择:
(1)windows自带的工具(运行MSTSC命令打开)
(2)mobaxterm

参考:https://www.cnblogs.com/lhlucky/p/yclj.html

2、使用xdcmp协议

(1)apt-get install xubuntu-desktop
(2)cp    /usr/share/doc/lightdm//lightdm.conf.gz      /etc/lightdm/
(3)修改配置
找到#user-session=default改成user-session=xfce
找到[XDMCPServer],把下面的#enabled=false改成enabled=true
把下面的#port=177改成port=177
(4)修改/usr/share/lightdm/lightdm.conf.d/60-xubuntu.conf为
[Seat:*]
user-session=xubuntu
greeter-show-manual-login=true
[XDMCPServer]
enabled=true
(4)service lightdm restart    netstat -anp | grep177查看是否启动

遇到问题:
用xmanager连接自己的配置好的虚拟机可以,用mobaxterm连接失败;
用xmanager、mobaxterm连接配置好的公有IP服务器失败,还不知道原因

参考:https://blog.csdn.net/lonelysky/article/details/54924156
https://ithelp.ithome.com.tw/questions/10189360

3、vscode安装

此种使用xrdp远程连接情况下为服务器安装vscode后,极有可能出现如下错误:
Xlib: extension "XInputExtension" missing on display ":10.0".
Xlib: extension "XInputExtension" missing on display ":10.0".

解决方法:
mkdir ~/lib
cp /usr/lib/x86_64-linux-gnu/libxcb.so.1 ~/lib                                 //备份
sed -i 's/BIG-REQUESTS/_IG-REQUESTS/' ~/lib/libxcb.so.1       //将~/lib/libxcb.so.1内的BIG-REQUESTS修改为_IG-REQUESTS
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH   //将~/lib加到标准动态库的搜索路径
code            //打开vscode

参考:https://blog.csdn.net/zaq15csdn/article/details/91631356
此篇作者也是从GitHub上找到的答案,GitHub原文为:https://github.com/microsoft/vscode/issues/3451

补充:
LIBRARY_PATH:是程序编译期间查找动态链接库时指定查找共享库的路径,即静态库路径
LD_LIBRARY_PATH:是程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径,即动态库路径
参考:https://www.imooc.com/article/43747

export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH只是临时修改LD_LIBRARY_PATH,若想永久性更改需要将其加到/etc/profile、/etc/export、~/.bashrc 或者 ~/.bash_profile中
参考:https://www.jianshu.com/p/a62e1d327023

4、调试C++代码

在项目根目录下创建.vscode文件下,文件下有task.json、launch.json、settings.json三个文件,模板如下:

task.json:
{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            //    执行工程文件夹下面的build.sh脚本
            "command": "sh ${workspaceFolder}/make_vpaas.sh",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

launch.json:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            //    去bin文件夹找可执行文件
            "program": "${workspaceFolder}/bin/${fileBasenameNoExtension}/${fileBasenameNoExtension}",
            //    每次执行命令行参数在argc中输入
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

settings.json
{
    "files.associations": {
        "stdio.h": "c",
        "iostream": "cpp"
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值