在Windows Subsystem for Linux(WSL)下配置OpenGL开发环境和x11转发

(1)打开启用或关闭windows功能中的Windows Subsystem for Linux




(2)在微软商店中找到ubuntu18并安装

(3)安装完成后启动,等待Ubuntu子系统安装完成,设置用户名密码

(4)设置root密码

1
sudo passwd root

(5)设置ssh连接

修改

1
sudo vim /etc/ssh/sshd_config

至如下(ubuntu的窗口颜色可以右键标题栏修改)

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    #   $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 8022
#AddressFamily any
ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:
AllowUsers azuse
AllowUsers root
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication no

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem   sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server

然后生成一个sshkey并重启ssh服务

1
2
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
sudo service ssh restart

重启ssh

(5)从windows的term连接

选择自己喜欢的终端,我使用的是mobaXterm,设置连接ip为127.0.0.1,端口为8022,用户可以是root也可以是你刚才安装时创建的用户

然后连接,现在应该已经可以正常连上主机了

(6)修改ubuntu子系统的apt源

1
/etc/apt/sources.list

修改为如下

1
2
3
4
5
6
7
8
9
10
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

(7)安装各种依赖

1
2
3
4
5
6
apt update
apt install libglew-dev
apt install gcc-multilib
apt-get install mesa-utils
apt-get install freeglut3-dev
apt-get install -y build-essential

注:安装liblew-dev的过程可能会出错,有一个deb需要自己安装

1
2
3
    wget http://172.21.0.162/files/316000000002F31A/cdn.packages.deepin.com/deepin/pool/main/libx/libxext/libxext-dev_1.3.3-1_amd64.deb
    dpkg --force-depends -i libxext-dev_1.3.3-1_amd64.deb
    apt --fix-broken install

(8)上传老师的文件,并编译

上传zip文件夹,

1
apt install zip

然后

1
unzip firstogl.zip

然后打开firstogl文件夹

1
2
3
apt install cmake -y
cmake .
make

之后在firstogl/bin中应该生成了可执行文件

(9)设置x11转发,显示ubuntu的图形界面

安装VcXsrv并启动Xlaunch

https://sourceforge.net/projects/vcxsrv/files/latest/download

启动时选择Multiple windows

在ubuntu中输入

1
 export DISPLAY=:0

启动编译好的二进制文件

1
2
        cd bin/
        ./firstOglDemo

正常运行,如图


Leave a comment

电子邮件地址不会被公开。 必填项已用*标注