准备工作:
MSYS2是Webots在Windows上的主要开发环境:
● 从 https://msys2.github.io 安装 MSYS2(选择 64 位版本并按照说明进行操作)。
● 不要忘记使用下面命令更新包数据库。
pacman -Syu
● 使用下面命令安装 Git .
pacman -S git
1、克隆源代码
管理员运行MINGW64,执行:
git clone https://github.com/zanxueyan/webots.git
上述地址是我自己fork的官网源代码,你也可以先fork后克隆自己的库
2.Git 子模块
如果您使用–recurse-submodules该选项克隆了 Webots,则可以跳过此步骤。 否则,您需要初始化 Webots 使用的子模块,:
cd webots
git submodule init
git submodule update
这个环节如果报错,一般是网络问题,重复执行对应命令即可。
3.设置您的 bash 个人资料
在末尾附加并检查和编辑结果:scripts/install/bash_profile.windows~/.bash_profile
cat scripts/install/bash_profile.windows >> ~/.bash_profile
重新启动 MSYS2。
4.安装 MSYS2 依赖项
首先cd到webots目录下
cd D:\webots
scripts/install/msys64_installer.sh
5.构建webots
执行下面代码开始编译webots,默认的是执行release
make -j12
如果需要编译为调试版本,请使用
make -j12 debug
一般windows编译会出现下方的错误:
Makefile:58: `pwd -W | tr -s / '//'`/resources/Makefile.os.include: No such file or directory
make: *** No rule to make target '`pwd -W | tr -s / '//'`/resources/Makefile.os.include'. Stop.
需要打开根目录下的Makefile文件,按照第18行提示,需要将WEBOTS_HOME地址改为自己的路径,例如我下载到D:\webots,则将第19行改为:
export WEBOTS_HOME:=D:\webots
再次执行make -j12,开始编译,编译过程中出现如下错误
Traceback (most recent call last):
File "D:\webots\scripts\packaging\generate_proto_liTraceback (most recent call last):
File "D:\webots\scripts\packaging\generate_proto_list.py", line 240, in <module>
generate_proto_list(tag)
File "D:\webots\scripts\packaging\generate_proto_list.py", line 142, in generate_proto_list
info = ProtoInfo(str(asset), asset.stem)
File "D:\webots\scripts\packaging\generate_proto_list.py", line 48, in __init__
self.contents = file.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 357: illegal multibyte sequence
make: *** [Makefile:128: webots_dependencies] Error 1
按错误提示,打开D:\webots\scripts\packaging\generate_proto_list.py,在第48行,因为编码问题报错,修改为如下;
with open(self.path, 'r',encoding='UTF-8') as file:
再次执行make -j12,即可开始编译,最终出现报错
# linking D:/webots/lib/controller/Controller.dll
# linking D:/webots/lib/controller/libController.a
# creating D:/webots/lib/controller/Controller.lib
/bin/sh: line 1: lib: command not found
make[2]: *** [Makefile:133: D:/webots/lib/controller/Controller.lib] Error 127
make[1]: *** [Makefile:23: release] Error 2
make: *** [Makefile:119: webots_projects] Error 2
打开文件夹,发现第一个dll和第二.a文件均生成,但是没有生成lib文件,因此下面报错找不到这个文件。
目前为止没有找到原因和解决方案,拜托各位看官给与支持。
续写***
再次编译过程中,注意到提示报错:
'VISUAL_STUDIO_PATH' not set,skipping Controller.lib
最近百度了一下这个问题,找到本链接,大家可以尝试一下