Windows下编译coal

文章目录

目前在使用mujoco时发现其碰撞是使用凸包进行碰撞检测的,这样一来,对于一些机械零件、带孔洞的物体就无法正确地进行碰撞检测了。

经过查找资料,发现这个开源库【coal:An extension of the Flexible Collision Library】能够实现精确的物体碰撞检测。

经过测试,将coal与mujoco进行结合,能够实现必要的运动仿真+精确的碰撞检测,能够满足我的机器人仿真平台的实现。

下面简单记录一下如何编译coal。

1.前置条件

我使用的工具如下所示

工具 路径 / 版本
CMake 4.3.0(D:/Program Files/CMake
MSVC 2019 D:/Program Files (x86)/Microsoft Visual Studio/2019/Community
vcpkg 依赖 D:/Utils/vcpkg/packages
vcvars64 D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat

以下所有命令均在 Developer Command Prompt for VS 2019 (或已执行 vcvars64.bat 的终端)中运行。


2.第三方依赖(vcpkg)

Coal 编译依赖以下第三方库,需通过 vcpkg 安装(triplet: x64-windows):

必须依赖

vcpkg 包 CMake 包 说明
eigen3 Eigen3 (≥ 3.0.0) 线性代数
boost-serialization Boost.Serialization 序列化
boost-filesystem Boost.Filesystem 文件系统操作
assimp assimp 3D 模型导入

安装命令:

powershell 复制代码
vcpkg install eigen3 boost-serialization boost-filesystem assimp --triplet x64-windows

可选依赖

vcpkg 包 CMake 包 对应 CMake 选项 说明
boost-log Boost.Log COAL_ENABLE_LOGGING=ON 日志
octomap octomap (≥ 1.8.0) 自动检测 八叉树碰撞
qhull Qhull COAL_HAS_QHULL=ON 凸包计算

构建期自动拉取(无需 vcpkg)

名称 来源 说明
jrl-cmakemodules GitHub FetchContent CMake 辅助模块

满足上面的前置条件后,就可以开始编译了

3.编译及安装

到某个空白文件夹下,打开控制台窗口,依次执行以下执行

下载coal源码

bash 复制代码
git clone https://github.com/coal-library/coal.git

激活vc编译环境(注意带引号),具体路径得看你vs的安装位置

bash 复制代码
"D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat"

将后面的脚本保存为build-both.bat,放在当前目录下,然后执行。

bash 复制代码
build-both.bat 

这个脚本会先编译release版本、然后编译debug版本,然后将编译好的库安装到当前目录下的install文件夹。

如下图所示

文件/文件夹 说明
build 编译时产生的中间文件
coal coal源码
install 编译后的库安装到的位置,后面第三方就可以直接使用这里面的东西
build-both.bat 主导编译的脚本
bash 复制代码
@echo off
setlocal

set PREFIX_PATH=D:/Utils/vcpkg/packages/boost-cmake_x64-windows/share/boost;D:/Utils/vcpkg/packages/eigen3_x64-windows/share/eigen3;D:/Utils/vcpkg/installed/x64-windows

:: Source dir is coal/ (relative to the parent dir where this script runs)
set SRC=coal

:: ---- Release ----
echo ===== Configuring Release =====
cmake -S %SRC% -B build\release -DCMAKE_PREFIX_PATH="%PREFIX_PATH%" -DBUILD_PYTHON_INTERFACE=OFF -DBUILD_TESTING=OFF
if %ERRORLEVEL% NEQ 0 (
    echo [WARN] CMake failed. Patching boost.cmake...
    powershell -Command "(Get-Content 'build/release/_deps/jrl-cmakemodules-src/boost.cmake') -replace 'Boost_NO_BOOST_CMAKE ON','Boost_NO_BOOST_CMAKE OFF' | Set-Content 'build/release/_deps/jrl-cmakemodules-src/boost.cmake'"
    cmake -S %SRC% -B build\release -DCMAKE_PREFIX_PATH="%PREFIX_PATH%" -DBUILD_PYTHON_INTERFACE=OFF -DBUILD_TESTING=OFF
)
echo ===== Building Release =====
cmake --build build\release --config Release -- /m

:: ---- Debug ----
echo ===== Configuring Debug =====
cmake -S %SRC% -B build\debug -DCMAKE_PREFIX_PATH="%PREFIX_PATH%" -DBUILD_PYTHON_INTERFACE=OFF -DBUILD_TESTING=OFF
if %ERRORLEVEL% NEQ 0 (
    echo [WARN] CMake failed. Patching boost.cmake...
    powershell -Command "(Get-Content 'build/debug/_deps/jrl-cmakemodules-src/boost.cmake') -replace 'Boost_NO_BOOST_CMAKE ON','Boost_NO_BOOST_CMAKE OFF' | Set-Content 'build/debug/_deps/jrl-cmakemodules-src/boost.cmake'"
    cmake -S %SRC% -B build\debug -DCMAKE_PREFIX_PATH="%PREFIX_PATH%" -DBUILD_PYTHON_INTERFACE=OFF -DBUILD_TESTING=OFF
)
echo ===== Building Debug =====
cmake --build build\debug --config Debug -- /m

:: ---- Install ----
echo ===== Installing =====
if exist install rmdir /s /q install

:: 1. Install Release (headers + libs + cmake config)
echo --- Installing Release ---
cmake --install build\release --config Release --prefix install

:: 2. Install Debug to temp, then extract only libs/binaries to install/debug/
echo --- Installing Debug ---
cmake --install build\debug --config Debug --prefix install_debug_tmp
if not exist install\debug\lib mkdir install\debug\lib
if not exist install\debug\bin mkdir install\debug\bin

:: Copy only Debug .lib / .dll / .pdb to debug subdir (never headers or cmake config)
robocopy install_debug_tmp\lib install\debug\lib *.lib *.pdb /mov /njh /njs /nfl >nul
robocopy install_debug_tmp\bin install\debug\bin *.dll *.pdb /mov /njh /njs /nfl >nul

:: Remove temp dir (any leftover files like cmake config, headers)
rmdir /s /q install_debug_tmp

echo ===== Done =====
echo.
echo Install layout:
echo   install\include\    -- shared headers
echo   install\lib\        -- Release .lib + cmake config
echo   install\bin\        -- Release .dll
echo   install\debug\lib\  -- Debug .lib
echo   install\debug\bin\  -- Debug .dll
endlocal
相关推荐
qq_3692243314 天前
Windows全系通用!ntdll.dll文件丢失、报错、闪退问题的完整排查与修复教程
windows·dll·dll修复·dll丢失·dll错误
阿米亚波14 天前
【Windows】QEMU 启动 openEuler aarch64/arm64 架构系统 + 离线软件源
linux·windows·经验分享·笔记·架构·arm
caimouse14 天前
Reactos 第 10 章 网络操作 — 10.3.1 NIC驱动
网络·windows
初圣魔门首席弟子14 天前
Node.js 详细介绍(知识库版)
windows·qt·node.js·知识库
CHENG-JustDoIt15 天前
AI工具 | 爆火开源项目Odysseus AI 工作台:从项目介绍、部署情况及其使用等多方位分析指南(含详细步骤)
大数据·人工智能·windows·python·ai·开源·github
kingbal15 天前
Windows:flutter环境搭建
windows·flutter
未若君雅裁15 天前
Python 数据容器详解,list、tuple、str、set、dict 到底怎么选
windows·python·list
CodeKwang15 天前
Windows 环境 OCCT 8.0 编译构建及与 Qt6 项目集成
windows·qt·opencascade
我是伪码农15 天前
小兔鲜1-25
linux·服务器·windows
vx-Biye_Design15 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis