Help - Search - Members - Calendar
Full Version: using of own C Bibliothek
Modelica Forum > Modelica > MathModelica / OpenModelica
Enrico Straube
Hello,

I want to use my own c library in my model. I use it now with Dymola but I also want to use it in OpenModelica.

Here are the current code.
CODE

function MyFunc
  input SI.Length l;
  input SI.Radius r;
  input SI.Length b;
  output SI.Length myfunc;
//  external "C" myfunc=myfunc(l,r,b) annotation(Library="../vendor/libmylib.a",Include="#include \"../vendor/mylib.h\"");
  external "C" annotation(Library="mylib",Include="#include \"mylib.h\"");
end Hub;


The problem is, that i don't want to copy the lib and the header in the Dymola directory. I want to use th relative path to that files (like the comment in the above code block.

Please help me.

When is OpenModelica ready for Modelica 3.0?

Thank you for you help.
Enrico
wagner
Hello Enrico,

what do you mean with Dymola directory?

Usually you can put your external libraries and source codes in the project directory of your modelica model and it will be found by the compiler. Then you can use Dymola and OpenModelica without changing anything.

Regards

Florian
Enrico Straube
ZITAT(wagner @ Oct 31 2007, 08:49 AM) *

what do you mean with Dymola directory?

Usually you can put your external libraries and source codes in the project directory of your modelica model and it will be found by the compiler. Then you can use Dymola and OpenModelica without changing anything.


I have here an other directory structure. So I copied the files (*.a, *.h) in the Dymola directory. I would like to use relativ path in the sources to use the library.

Here a sample directory structure.

QUELLTEXT

./project/
./project/modelica/div. package/*.mo
./project/vendor/*.a, *.h


So I hope to use the library directly from the vendor directory.

I hope you understand me now.

Regards

Enrico
Jawhar
QUOTE(Enrico Straube @ Nov 2 2007, 02:39 PM) *

I have here an other directory structure. So I copied the files (*.a, *.h) in the Dymola directory. I would like to use relativ path in the sources to use the library.

Here a sample directory structure.

CODE

./project/
./project/modelica/div. package/*.mo
./project/vendor/*.a, *.h


So I hope to use the library directly from the vendor directory.

I hope you understand me now.

Regards

Enrico


I am sur of one thing:
When you had to use a library in OpenModelica you had to creat it in the ~/OpenModelica/share/openmodelica-1.4-dev/bin. So when you creat your *.mos you can put something like this:

system("gcc -c -o .../OpenModelica/share/openmodelica-1.4-dev/bin/mylibrary.a .../OpenModelica/MyFolder/mylibrary.c");

when execute your program with line command omc using the mos file, the library will be created in the bin directory. And in your code in the mo file you will use something like this:
external "C" annotation(Library="mylibrary",Include="#include \\"../vendor/mylib.h\"");

This is tested under OpenModelica 1.4.3

hope this can help you!

Regards,

Jawhar
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.