How to make my application derivable

From KratosWiki
Jump to: navigation, search

Contents

How to make my application derivable

It has been always possible to make applications use code from other applications in Linux without further modification. Although, when compiling under windows environments this can be a little bit tricky since by default MSVC compiler does not export any symbol. In other words your applications are black boxes and no one can access its contents.

KratosMultiphysics provides a method to automate as much as possible the process of make your application derivable in windows.

There are only a couple small things that you need to take into account:

Define you application name

The first thing you need to do is to indicate the compiler that you are going to allow the application to be derived. This is done by defining the name of your application with the value "EXPORT,API" in the CMakeLists.txt file. This is step is also mandatory if you want to make derivable any class in your application, even though it is not the application itself.

Add the following line in the file CMakeLists.txt of your application:

 set_target_properties(KratosFooApplication PROPERTIES COMPILE_DEFINITIONS "FOO_APPLICATION=EXPORT,API")

Export your variables

In order to make your variables visible, you will need to change its declaration with the define name from the step 1. We provide a couple of replacements for do that:

KRATOS_DEFINE_VARIABLE
KRATOS_DEFINE_3D_VARIABLE_WITH_COMPONENTS

will become:

KRATOS_DEFINE_APPLICATION_VARIABLE
KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS

For example:

KRATOS_DEFINE_VARIABLE(int, VAR_1)

will become

KRATOS_DEFINE_APPLICATION_VARIABLE(FOO_APPLICATION, int, VAR_1)

Export your classes

Finally you will also need to indicate which classes are available to be used from other applications. In order to do it you will need to use the KRATOS_API() macro with the define name of your applications in the declaration of the class.

For example

 class myclass() {
 }

will become:

 class KRATOS_API(FOO_APPLICATION) myclass() {
 }

If your class depends on a template parameter, you will also need to instantiate such class, as no code exists in compile time and otherwise will be impossible to export:


For instance, if you want to use class myclass with double:

 temaplte<class T>
 class myclass() {
    ...
 };

becomes

 temaplte<class T>
 class KRATOS_API(FOO_APPLICATION) myclass() {
    ...
 };
 
 ...
 
 template class KRATOS_API(FOO_APPLICATION) myclass<double>;
Personal tools
Categories