Difference between revisions of "Including this library in your project"

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
(Using in a cmake project)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
=== Using in a cmake project ===
 +
 
Integration with our library is very simple if you are using <code>cmake</code>.
 
Integration with our library is very simple if you are using <code>cmake</code>.
 
Your basic <code>CMakeLists.txt</code> file should look something like this:
 
Your basic <code>CMakeLists.txt</code> file should look something like this:
Line 5: Line 7:
 
project(your_project_name)
 
project(your_project_name)
 
cmake_minimum_required(VERSION 2.8.12)
 
cmake_minimum_required(VERSION 2.8.12)
 +
 +
add_compile_options(-std=c++11 -Wall -O3 -fopenmp)  # modify flags appropriately for your project
 +
# add_compile_definitions(NDEBUG)  # disable asserts
  
 
add_subdirectory(${CMAKE_SOURCE_DIR}/path/to/medusa/ medusa) # add our library's CMakeLists.txt as a subfolder
 
add_subdirectory(${CMAKE_SOURCE_DIR}/path/to/medusa/ medusa) # add our library's CMakeLists.txt as a subfolder
Line 12: Line 17:
 
add_executable(my_name my_name.cpp)
 
add_executable(my_name my_name.cpp)
 
target_link_libraries(my_name medusa)  # link to our library
 
target_link_libraries(my_name medusa)  # link to our library
 +
</syntaxhighlight>
 +
 +
 +
Next to the <code>CMakeLists.txt</code> file, you should put your source file <code>my_name.cpp</code>,
 +
which can now use the Medusa library. Sample contents of the file are shown below:
 +
 +
<syntaxhighlight lang="cpp">
 +
#include <medusa/Medusa.hpp>
 +
#include <iostream>
 +
 +
using namespace mm;
 +
 +
int main() {
 +
    BoxShape<Vec2d> box(0, 1);
 +
    std::cout << box << std::endl;
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
 +
The code is then compiled by going to your build directory and writing <code>make my_name</code>.
 +
 +
=== Standalone usage ===
 +
 +
By running <code>make medusa_standalone</code> in the <code>medusa/build</code> directory, the static archive
 +
<code>medusa/bin/libmedusa_standalone.a</code> is created. In you project, you have to include the medusa headers
 +
<code>#include <medusa/Medusa.hpp></code>, point to their directory
 +
<code>medusa/include/</code> and link the <code>medusa_standalone</code> library.
 +
 +
<syntaxhighlight lang="bash">
 +
g++ -o my_program my_program.cpp -I /.../medusa/include -L /.../medusa/bin/ -lmedusa_standalone
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 13:34, 16 August 2019

Using in a cmake project

Integration with our library is very simple if you are using cmake. Your basic CMakeLists.txt file should look something like this:

project(your_project_name)
cmake_minimum_required(VERSION 2.8.12)

add_compile_options(-std=c++11 -Wall -O3 -fopenmp)  # modify flags appropriately for your project
# add_compile_definitions(NDEBUG)  # disable asserts

add_subdirectory(${CMAKE_SOURCE_DIR}/path/to/medusa/ medusa) # add our library's CMakeLists.txt as a subfolder
include_directories(${CMAKE_SOURCE_DIR}/path/to/medusa/include/)  # include medusa headers directory

# define your own executables below
add_executable(my_name my_name.cpp)
target_link_libraries(my_name medusa)  # link to our library


Next to the CMakeLists.txt file, you should put your source file my_name.cpp, which can now use the Medusa library. Sample contents of the file are shown below:

#include <medusa/Medusa.hpp>
#include <iostream>

using namespace mm;

int main() {
    BoxShape<Vec2d> box(0, 1);
    std::cout << box << std::endl;
    return 0;
}

The code is then compiled by going to your build directory and writing make my_name.

Standalone usage

By running make medusa_standalone in the medusa/build directory, the static archive medusa/bin/libmedusa_standalone.a is created. In you project, you have to include the medusa headers #include <medusa/Medusa.hpp>, point to their directory medusa/include/ and link the medusa_standalone library.

g++ -o my_program my_program.cpp -I /.../medusa/include -L /.../medusa/bin/ -lmedusa_standalone