Skip to content

Commit c6297dc

Browse files
alesofAddisu Z. Taddeseahcorde
authored
Update tutorial build step (#626)
* Update cppgetstarted.md Unifies building steps for unix and win using cmake. Signed-off-by: Alessandro Sofia <al.sofia@studenti.unina.it> * Fix make directive Update to build it from windows Signed-off-by: Alessandro Sofia <al.sofia@studenti.unina.it> * Update tutorials/cppgetstarted.md Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> Signed-off-by: Alessandro Sofia <al.sofia@studenti.unina.it> * Apply suggestions from code review Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org> --------- Signed-off-by: Alessandro Sofia <al.sofia@studenti.unina.it> Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
1 parent c35a71a commit c6297dc

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

tutorials/cppgetstarted.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,43 @@ int main()
6767
}
6868
```
6969

70-
To compile this code on UNIX with pkg-config, use the following command:
70+
To compile the code create a `CMakeLists.txt`:
7171

7272
```{.bash}
73-
c++ $(pkg-config --cflags gz-math8) main.cpp -o main
73+
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
74+
project(gz-math-cpp-example)
75+
76+
find_package(gz-math8 QUIET REQUIRED)
77+
78+
add_executable(gz-math-example main.cpp)
79+
target_link_libraries(gz-math-example PUBLIC gz-math8::gz-math8)
7480
```
7581

76-
The program can then be run as:
82+
Compile the example:
83+
84+
```{.bash}
85+
mkdir build && cd build
86+
cmake ..
87+
```
88+
89+
For Unix systems:
90+
91+
```{.bash}
92+
make
93+
94+
For Windows systems:
95+
96+
```{.bash}
97+
cmake --build . --config Release
98+
99+
Run the example:
100+
101+
```{.bash}
102+
./gz-math-example
103+
```
77104

105+
Output should be:
78106
```{.bash}
79-
$ ./main
80107
Distance from 1 3 5 to 2 4 6 is 1.73205
81108
```
82109

0 commit comments

Comments
 (0)