From 5b85fc885f5a3966837f9b9fcfd0dfbde5715e7b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 17 May 2019 12:15:10 -0400 Subject: [PATCH 1/4] added required includes to fix compilation of matlab wrapper example --- cmake/example_project/example.h | 1 + cmake/example_project/example/PrintExamples.h | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/example_project/example.h b/cmake/example_project/example.h index 47b9a0aa2..eea1e13a5 100644 --- a/cmake/example_project/example.h +++ b/cmake/example_project/example.h @@ -20,6 +20,7 @@ namespace example { +#include class PrintExamples { void sayHello() const; void sayGoodbye() const; diff --git a/cmake/example_project/example/PrintExamples.h b/cmake/example_project/example/PrintExamples.h index b151dfbc7..25d4dd8cb 100644 --- a/cmake/example_project/example/PrintExamples.h +++ b/cmake/example_project/example/PrintExamples.h @@ -17,6 +17,7 @@ #pragma once +#include #include namespace example { From a743a4acc95940cd4421e5b7b68453cbd3c8dff8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 17 May 2019 18:29:35 -0400 Subject: [PATCH 2/4] change example_project .so file from STATIC to SHARED, and install library to /lib in install path --- cmake/example_project/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/example_project/CMakeLists.txt b/cmake/example_project/CMakeLists.txt index 2afc6edc2..620ad4811 100644 --- a/cmake/example_project/CMakeLists.txt +++ b/cmake/example_project/CMakeLists.txt @@ -30,9 +30,12 @@ find_package(GTSAM REQUIRED) # Uses installed package ################################################################################### # Build static library from common sources set(CONVENIENCE_LIB_NAME ${PROJECT_NAME}) -add_library(${CONVENIENCE_LIB_NAME} STATIC example/PrintExamples.h example/PrintExamples.cpp) +add_library(${CONVENIENCE_LIB_NAME} SHARED example/PrintExamples.h example/PrintExamples.cpp) target_link_libraries(${CONVENIENCE_LIB_NAME} gtsam) +# Install library +install(TARGETS ${CONVENIENCE_LIB_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) + ################################################################################### # Build tests (CMake tracks the dependecy to link with GTSAM through our project's static library) gtsamAddTestsGlob("example" "tests/test*.cpp" "" "${CONVENIENCE_LIB_NAME}") From e985e2c95df1386b216b3d37efec1ad86c8c5e65 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 17 May 2019 18:30:19 -0400 Subject: [PATCH 3/4] added default constructor for PrintExamples --- cmake/example_project/example.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/example_project/example.h b/cmake/example_project/example.h index eea1e13a5..b0d732e14 100644 --- a/cmake/example_project/example.h +++ b/cmake/example_project/example.h @@ -18,12 +18,14 @@ // This is an interface file for automatic MATLAB wrapper generation. See // gtsam.h for full documentation and more examples. +#include + namespace example { -#include class PrintExamples { - void sayHello() const; - void sayGoodbye() const; + PrintExamples(); + void sayHello() const; + void sayGoodbye() const; }; } From 60b874b997496f4d4eeb032e2a49053d715662fa Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 17 May 2019 18:38:15 -0400 Subject: [PATCH 4/4] README for compiling and using the example_project --- cmake/example_project/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 cmake/example_project/README.md diff --git a/cmake/example_project/README.md b/cmake/example_project/README.md new file mode 100644 index 000000000..a1269cf19 --- /dev/null +++ b/cmake/example_project/README.md @@ -0,0 +1,32 @@ +# MATLAB Wrapper Example Project + +This project serves as a lightweight example for demonstrating how to wrap C++ code in MATLAB using GTSAM. + +## Compiling + +We follow the regular build procedure inside the `example_project` directory: + +```sh +mkdir build && cd build +cmake .. +make -j8 +sudo make install + +sudo ldconfig # ensures the shared object file generated is correctly loaded +``` + +## Usage + +Now you can open MATLAB and add the `gtsam_toolbox` to the MATLAB path + +```matlab +addpath('/usr/local/gtsam_toolbox') +``` + +At this point you are ready to run the example project. Starting from the `example_project` directory inside MATLAB, simply run code like regular MATLAB, e.g. + +```matlab +pe = example.PrintExamples(); +pe.sayHello(); +pe.sayGoodbye(); +``` \ No newline at end of file