From b0179416b47bf5f9981c5e9f65cb04c2c50d08f2 Mon Sep 17 00:00:00 2001 From: Alessandro Sofia Date: Fri, 30 Aug 2024 22:41:04 +0200 Subject: [PATCH 1/3] Update cppgetstarted.md Unifies building steps for unix and win using cmake. Signed-off-by: Alessandro Sofia --- tutorials/cppgetstarted.md | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tutorials/cppgetstarted.md b/tutorials/cppgetstarted.md index 39afb8f7..9bc8693f 100644 --- a/tutorials/cppgetstarted.md +++ b/tutorials/cppgetstarted.md @@ -67,19 +67,38 @@ int main() } ``` -To compile this code on UNIX with pkg-config, use the following command: +To compile the code create a `CMakeLists.txt`: -```{.bash} -c++ $(pkg-config --cflags gz-math8) main.cpp -o main +``` +cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) +project(gz-math-cpp-example) + +find_package(gz-math8 QUIET REQUIRED) + +add_executable(gz-math-example main.cpp) +target_link_libraries(gz-math-example ${GZ-MATH_LIBRARIES}) ``` -The program can then be run as: +Compile the example: + +``` +mkdir build && cd build +cmake .. +make +``` + +Run the example: ```{.bash} -$ ./main +./gz-math-example +``` + +Output should be: +```{.bash} Distance from 1 3 5 to 2 4 6 is 1.73205 ``` + ## Bonus: Vector2 Example The following is an example program that uses Vector2 to perform some simple From b5ca0ad09eba0dad1f31a1ab37e25b33c536ccae Mon Sep 17 00:00:00 2001 From: Alessandro Sofia Date: Fri, 30 Aug 2024 23:07:38 +0200 Subject: [PATCH 2/3] Fix make directive Update to build it from windows Signed-off-by: Alessandro Sofia --- tutorials/cppgetstarted.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tutorials/cppgetstarted.md b/tutorials/cppgetstarted.md index 9bc8693f..557af85c 100644 --- a/tutorials/cppgetstarted.md +++ b/tutorials/cppgetstarted.md @@ -84,9 +84,18 @@ Compile the example: ``` mkdir build && cd build cmake .. +``` + +For Unix systems: +``` make ``` +For Windows systems: +``` +cmake --build . --config Release +``` + Run the example: ```{.bash} From 0cedd81826c8857aa3702dedae1878a255b3d72a Mon Sep 17 00:00:00 2001 From: Alessandro Sofia Date: Sat, 31 Aug 2024 17:49:25 +0200 Subject: [PATCH 3/3] Update tutorials/cppgetstarted.md Co-authored-by: Addisu Z. Taddese Signed-off-by: Alessandro Sofia --- tutorials/cppgetstarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/cppgetstarted.md b/tutorials/cppgetstarted.md index 557af85c..9fa5a07f 100644 --- a/tutorials/cppgetstarted.md +++ b/tutorials/cppgetstarted.md @@ -76,7 +76,7 @@ project(gz-math-cpp-example) find_package(gz-math8 QUIET REQUIRED) add_executable(gz-math-example main.cpp) -target_link_libraries(gz-math-example ${GZ-MATH_LIBRARIES}) +target_link_libraries(gz-math-example PUBLIC gz-math8::gz-math8) ``` Compile the example: