在Ubuntu上编译MRPT教程

Compiling MRPT tutorial on Ubuntu

本文关键字:MRPT 教程 编译 Ubuntu      更新时间:2023-10-16

我正在学习在Ubuntu上使用C++的MRPT库的教程,但我还没有走多远。我根据http://www.mrpt.org/MRPT_in_GNU/Linux_repositories

现在,我正在学习从这个链接用MRPT编写第一个C++程序的教程

我在一个目录中下载并解压了mrpt_example1.tar.gz,但当我使用以下命令运行时:

ccmake .

没有生成代码的选项。MRPT_DIR已经设置为/usr/share/mrpt,即MRPTConfig.cmake的位置,所以ccmake似乎已经找到了那个位置。我尝试设置其他选项,如CMAKE_BUILD_TYPEEXECUTABLE_OUTPUT_PATHLIBRARY_OUTPUT_PATH,但没有帮助。

如何告诉ccmake实际编译?

您可以直接使用cmake,而不是使用ccmake,如下所示:

cmake .

这将在当前目录中生成一个Makefile

$ ls -1
CMakeCache.txt
CMakeFiles
cmake_install.cmake
CMakeLists.txt
Makefile
README.txt
test.cpp

然后,您可以运行make来编译示例程序:

$ make
Scanning dependencies of target mrpt_example1
[ 50%] Building CXX object CMakeFiles/mrpt_example1.dir/test.o
[100%] Linking CXX executable mrpt_example1
[100%] Built target mrpt_example1

然后运行示例程序:

$ ./mrpt_example1
L: (0,4,2)
R: (2.000,1.000,45.00deg)
C: (x,y,z,yaw,pitch,roll)=(0.5000,0.5000,1.5000,-90.00deg,0.00deg,-90.00deg)
R+C:(x,y,z,yaw,pitch,roll)=(2.0000,1.7071,1.5000,-45.00deg,-0.00deg,-90.00deg)
Computation in: 0.0857 us
L': (-3.03553,-0.5,0.207107)
R(+)C(+)L' = (-5.82867e-16,4,2)
Should be equal to L = (0,4,2)
|(R(+)C)-L|= 3.0834
|L-(R(+)C)|= 3.0834

请注意,您应该从提取mrpt_example1.tar.gz内容的干净副本开始,并在干净副本中执行这些步骤。


或者,您可以使用示例项目的版本,该版本提供开箱即用的Makefile,并且不需要CMake:

https://github.com/MRPT/mrpt/tree/master/doc/mrpt_example1-with-Makefile

以下教程介绍了这一点:

http://www.mrpt.org/tutorials/programming/first-steps/compiling_custom_applications_in_linux_with_a_makefile_and_pkg-config/


否则,如果必须使用ccmake:

首先,提取mrpt_example1.tar.gz内容的干净副本。

输入提取的mrpt_example1目录并运行:

ccmake .

这将显示一个具有以下选项的交互式对话框:

Press [enter] to edit option
Press [c] to configure
Press [h] for help           Press [q] to quit without generating
Press [t] to toggle advanced mode (Currently Off)

c进行配置。屏幕顶部现在将显示:

CMAKE_BACKWARDS_COMPATIBILITY   *2.4
CMAKE_BUILD_TYPE                *
CMAKE_INSTALL_PREFIX            */usr/local
EXECUTABLE_OUTPUT_PATH          *
LIBRARY_OUTPUT_PATH             *
MRPT_DIR                        */usr/share/mrpt

c重新配置。以下选项现在可用:

Press [enter] to edit option
Press [c] to configure       Press [g] to generate and exit
Press [h] for help           Press [q] to quit without generating
Press [t] to toggle advanced mode (Currently Off)

g生成输出文件(包括Makefile)并退出。

请注意,已经生成了一个Makefile

$ ls -1
CMakeCache.txt
CMakeFiles
cmake_install.cmake
CMakeLists.txt
Makefile
README.txt
test.cpp

您可以运行make来编译示例程序,然后在编译完示例程序后运行该程序,如上所述。