## Adding source files to path

mandolini_
Posts: 15
Joined: Fri Feb 14, 2020 1:50 am

### Adding source files to path

I am new to plugin development. I have an algorithm in C++ that I wish to wrap into an MHA plugin and run in real time. I used one of the example plugins from

Code: Select all

{openMHA_root}/mha/plugins/
as a basis for my wrapper. I have all the necessary includes at the top of this file. How do I add my source code to the path so that it compiles as a .dylib file correctly?

Code: Select all

plugin.cpp:24:10: fatal error: 'algo.h' file not found
#include "algo.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [x86_64-Darwin-clang/mcwf.o] Error 1
make[1]: *** [mcwf] Error 2
make: *** [mha/plugins] Error 2

tobiasherzke
Posts: 44
Joined: Mon Jun 24, 2019 12:51 pm

### Re: Adding source files to path

Great that you want to run your code inside openMHA!

We have no header named "algo.h" in openMHA, therefore I cannot tell you where to find it. It should be part of your own code.

As for learning how to compile and link plugins for openMHA I would suggest that you delete one of the compiled plugins, call make again, and observe the command lines used by our build process to first compile the source code and then link the objects into a shared library.

mandolini_
Posts: 15
Joined: Fri Feb 14, 2020 1:50 am

### Re: Adding source files to path

Perhaps I should have been more clear. "algo.h" is the header file for my source code that I have included at the top of my plugin file ("plugin.cpp", which has been copied from one of the example plugins provided).

I believe what I am misunderstanding - and also where my question stems from - is how the compilation process works for creating new plugins from scratch. How should I go about linking my algorithm's source code (algo.cpp and algo.h) to the openMHA shared library you speak of? Am I blatantly misunderstanding how the different pieces of code fit together?

Thanks

tobiasherzke
Posts: 44
Joined: Mon Jun 24, 2019 12:51 pm

### Re: Adding source files to path

For this response I assume that you have followed the comilation instructions from https://github.com/HoerTech-gGmbH/openM ... ILATION.md, section on macOS:

You are interested manually compiling a new plugin that is not part of openMHA, particularly how to set the compiler search paths to compile and link a new, self-developed plugin.

I suggest that you compile the original openMHA source code following to these instructions. Compilation commands will scroll through your terminal while you do it, too many find a particular compilation task. To isolate the compilation commands for just one plugin in order to learn how we compile and link a plugin, please delete one of the compiled plugins when compilation is finished, e.g. with

Code: Select all

git clean -fdx mha/plugins/dc
then invoke make again to find just the commands needed to recompile this dc plugin. These will be (for release 4.11.0):

Code: Select all

clang++ -Wno-error=unused-command-line-argument -Wall -Wnon-virtual-dtor -Werror -std=c++14 -fPIC -O3 -msse -msse2 -mfpmath=sse -ffast-math -fomit-frame-pointer -fno-finite-math-only -I/opt/local/include -g -I/Users/mha/jenkins/workspace/openMHA_openMHA_master/external_libs/x86_64-Darwin-clang/include -I../../../external_libs/x86_64-Darwin-clang/include -I../../libmha/src -c -o x86_64-Darwin-clang/dc.o dc.cpp

clang++ -shared -o \$PWD/x86_64-Darwin-clang/dc.dylib x86_64-Darwin-clang/dc.o x86_64-Darwin-clang/dc_mha_git_commit_hash.o -L/Users/mha/jenkins/workspace/openMHA_openMHA_master/external_libs/x86_64-Darwin-clang/lib -L../../libmha/x86_64-Darwin-clang -L/opt/local/lib -lopenmha
These commands are executed inside the directory mha/plugins/dc. Unfortunately I cannot go into too much detail here what each of the options mean, please refer to the compiler's (clang or gcc) manual. As a rough overview: The first command compiles source code to object code and needs to be told where to find header files with option -I. The second command links object code into a shared library and links dependencies in with -L and -l options.

You will probably need to add more of these options for the compiler to find your headers and dependencies.

If you compile your plugin in another directory, i.e. not from inside mha/plugins/yourplugin, then you will also need to adjust all relative paths.

To future readers: These command lines will be different on other platforms (linux, windows, arm) and may change for future versions of openMHA. Please find compilation commands for your platform and version by following the described procedure instead of using the compilation commands from this forum post.

mandolini_
Posts: 15
Joined: Fri Feb 14, 2020 1:50 am

### Re: Adding source files to path

Thank you so much. This has been tremendously helpful.