Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Specify environnement for WINDOWS to use external lib.

Specify environnement for WINDOWS to use external lib.

Hi everybody,
I am a new user of OModelica and I want my model to communicate with an inhouse code.
My first goal is to make my model communicate through CORBA protocol. My OpenModelica can be look as a client of my application.

This how I want to built it.

First, I start with ExternalLibraries example found in /share/doc/omc/testmodels where I plug CORBA calls. I built my library libmylib.a with netbeans (not sure that we can make it dynamic ?) where mylib contains functions that need to use CORBA libraries.

Here is my OpenModelica model (unchanged) :

Code:

function ExternalFunc2

  input Real x;
  output Real y;
  external "C" annotation(Library="libmylib.a",Include="#include \"ExternalFunc2.h\"");
end ExternalFunc2;

model ExternalLibraries
  Real y(start=2.0);
equation
der(y)=-ExternalFunc2(y);
end ExternalLibraries;

Then, I launch this mos file :

Code:

loadFile("ExternalLibraries.mo");

#Compilation of static libraries is done in Netbeans, so I remove the compilation of object and librarie part : system("gcc -******" );
simulate(ExternalLibraries);

It fails with this error :

Code:


    messages = "Simulation failed for model: ExternalLibraries
Error: Error building simulator. Buildlog: gcc   -falign-functions -msse2 -mfpmath=sse   -I\"C:/Programfiles/OpenModelica//include
/omc\" -I.    -c -o ExternalLibraries.o ExternalLibraries.c
gcc   -falign-functions -msse2 -mfpmath=sse   -I\"C:/Programfiles/OpenModelica//include/omc\" -I.    -c -o ExternalLibraries_recor
ds.o ExternalLibraries_records.c
g++ -I. -o ExternalLibraries.exe ExternalLibraries.o ExternalLibraries_records.o -I\"C:/Programfiles/OpenModelica//include/omc\" -
I.    libmylib.a    -falign-functions -msse2 -mfpmath=sse   -L\"C:/Programfiles/OpenModelica//lib/omc\" -Wl,--stack,0x20
00000,-rpath,'C:/Programfiles/OpenModelica//lib/omc' -lSimulationRuntimeC   -linteractive  -lregex -lexpat -lgc  -static-libgcc -l
uuid -lole32 -lws2_32 -lsundials_kinsol -lsundials_nvecserial -llapack-mingw -ltmglib-mingw -lblas-mingw -Wl,-Bstatic -lf2c -Wl,-B
dynamic
libmylib.a(ExternalFunc2.o): In function `_static_initialization_and_destruction_0':
/cygdrive/C/omniORB-4.1.6/include/omnithread.h:674: undefined reference to `omni_thread::init_t::init_t()'
libmylib.a(ExternalFunc2.o): In function `_static_initialization_and_destruction_0':
/cygdrive/C/omniORB-4.1.6/include/omniORB4/finalCleanup.h:41: undefined reference to `_omniFinalCleanup::_omniFinalCleanup()'
/cygdrive/C/omniORB-4.1.6/include/omniORB4/finalCleanup.h:41: undefined reference to `_omniFinalCleanup::~_omniFinalCleanup()'
...

and many more.

For what I understand :
- Simulate launch g++
- g++ fails to find CORBA libraries

Questions :
1 - How can export all environment variables so simulate function/g++ can locate CORBA lib
1Bis - How to add compilation option to g++

2 - Could Netbeans replace simulate function, i.e. compile libs, exe and launch ? It would be easier for C-debugging. I am not using Eclipse since I don't want to use to many different IDE in this project.

3 - Is OModelica able to "use" dll ?

(4 - Can CORBA calls be made directly ? I know that OM use CORBA so more efficient ideas are welcome.)

Thanks in advance for your precious help
Thomas

Edited by: TP - Apr-04-13 16:17:40

Re: Specify environnement for WINDOWS to use external lib.

Where is libmylib.a located? You can put it either in C:/Programfiles/OpenModelica//lib/omc OR add the library path like this,

Code:

setEnvironmentVar("MODELICAUSERLFLAGS","-Lpath-to-library");

put the above line into your mos file.

Also, I think you must change

Code:

external "C" annotation(Library="libmylib.a",Include="#include \"ExternalFunc2.h\""); 

to

Code:

external "C" annotation(Library="mylib",Include="#include \"ExternalFunc2.h\""); 

Adeel.

Re: Specify environnement for WINDOWS to use external lib.

Library={"lib1","lib2","lib3"} can be used to add the dependencies (CORBA libs in this case).

You can use https://build.openmodelica.org/Document … Flags.html to add CFLAGS to the compiler as well. It might be possible to compiler the model through netbeans as well. Just add the code and try, but be warned the runtime libraries are linked against the mingw libc. Mixing the two does not always work.

Re: Specify environnement for WINDOWS to use external lib.

Thanks for your answers. I begin to understand how OpenModelica tries to facilitates things.
Indeed for me it's a bit tricky for my purpose current/smile

So, removing the letter "a" from the library name doesn't work.

I manage to launch the compilation process with Netbeans directly using the makefile generated. I remove some compilation problems by setting the right compiler.
sjoelund.se you were right when you said that we should care of runtime. Some links where not statisfied since Netbeans use by default Cygwin runtime on windows.
I had linking error like the one mentionned here. I configured Netbeans so it can use MSVCRT runtime. Where I would be able to find those information directly ?

Then, I wanted to add all corba libs (dynamic) :

Code:

LDFLAGS=-L"C:/Programfiles/OpenModelica//lib/omc" -Wl,--stack,0x2000000,-rpath,'C:/Programfiles/OpenModelica//lib/omc' $(LIBSIMULATIONRUNTIMEC) -linteractive  -lregex -lexpat -lgc  -static-libgcc -luuid -lole32 -lws2_32 -lsundials_kinsol -lsundials_nvecserial -llapack-mingw -ltmglib-mingw -lblas-mingw -Wl,-Bstatic -lf2c -Wl,-Bdynamic

I put manually -llibname after

Code:

-Bdynamic

but environnement variable are still not good... I should add

Code:

-L=C:/path/to/my/lib/

Both of your solution suggest that It can be done by mos-script. I look at it and be sure that CORBA lib is compiled with mingw/msys.

Re: Specify environnement for WINDOWS to use external lib.

Hmmm... There is a +target=msvc flag in OpenModelica. But I do not know what it will do since I use Linux current/smile
I'm guessing you need to compile the simulation runtime with msvc (the cmake targets). I have never tried that myself. I'll write an email to the developers mailing list and see if someone knows more.

Re: Specify environnement for WINDOWS to use external lib.

Hi,

as far I remember you need three thinks to compile the msvc targets if you compile omc on your own and one think if you use the installer. If you use the installer the visual studio compiler 9 is needed. If you compile omc on your own you need OMDev, CMake and visual studio 9.

Maybe the nmake file which is used to compile the simulator is not yet ready to use external libraries. But this should be easy to find out by checking the file.

Re: Specify environnement for WINDOWS to use external lib.

Hi,
thanks for all your answers. I was not able to test your suggestions but I will !

So far, I will post any findings/mistakes I made to contribute to this forum.

Thanks again.

Re: Specify environnement for WINDOWS to use external lib.

Hi,
I try to compile with omc +target=msvc file.mos

This command generates C-file in with a static function :

Code:


static void (*functionAlg_systems[0])(DATA *, int) = {
};

It fails to compile

Code:


error C2466: cannot allocate an array of constant size 0

with the command line :

Code:

cl /Od /ZI /EHa /fp:except /I\"C:/Programfiles/OpenModelica//include/omc\" /I. /DNOMINMAX /TP /DNO_INTERACTIVE_DEPENDENCY /c Test.Global.c 

which refers to the array :

Code:

functionAlg_systems[0]

.

I try with omc file.mos command and it compiles and works with the same code generated...

Any ideas ?

There are 0 guests and 0 other users also viewing this topic
You are here: