Compiling a model with cygwin or Rtools?

Use this forum to post Vensim related questions.
Post Reply
billh
Member
Posts: 45
Joined: Tue Jan 10, 2017 11:48 pm
Vensim version: DSS

Compiling a model with cygwin or Rtools?

Post by billh »

Has anyone successfully compiled a model using either an installed Cygwin or Rtools version of gcc? It's been awhile since I've written any compiled code.

I have installed Rtools over top of Cygwin on W7, which means my compiler is here:

Code: Select all

$ which gcc
/cygdrive/c/Rtools/gcc-4.6.3/bin/gcc
I saved my model in .vmf format, I commented out all of the compiler directory commands in mdl.bat, and I saved that in the same directory with my .vmf file.

When I told Vensim to compile the model, it gave me a "Stop from Vensim" message that said, "Failed to compile the model (does not exist)." It did produce the mdl.c file.

I then naively set the three directory variables:

Code: Select all

set PATH=/cygdrive/c/Rtools/gcc-4.6.3/bin
set LIB=/cygdrive/c/Rtools/gcc-4.6.3/lib
set INCLUDE=/cygdrive/c/Rtools/gcc-4.6.3/include
and that got me the same error message.

Tips?

Thanks.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Compiling a model with cygwin or Rtools?

Post by Administrator »

First delete the MDL.BAT file that you copied to the model folder, it will not get called.

What you need to do is figure out what commands are needed to compile mdl.c into a DLL. Start a command prompt and change to the folder with the mdl.c that you already have. Then figure out what commands are needed. These then need to be placed in the existing MDL.BAT replacing the Microsoft compiler commands with the gcc ones.

If it helps, this can be done on the Mac which uses gcc, I've pasted in the Mac version of MDL.BAT below as the commands should be very similar

Code: Select all

#!/bin/sh
#
# compile mdl.c and link to form libmdlname.dylib shared object library
# unlike Windows there is no actaul console, so no point in waiting
# on error. If errors do occur try
# /Users/Shared/Vensim/comp/mdl.macx /Users/Shared/Vensim/comp libtest
# from the directory with mdl.c (that is the model)
#
if [ -n "$3" ]
then outf="$3".dylib
else outf=libsim.dylib
fi
if [ -e "$outf" ] 
then rm "$outf"
fi
if [ -n "$2" ] 
then gcc -O2 -m32 -Dunix -dynamiclib mdl.c -I "$2" -o "$outf"
else gcc -O2 -m32 -Dunix -dynamiclib mdl.c -o $outf
fi
if [ -e "$outf" ] 
then echo "Successfully compiled"
else echo "Errors in compiling."
fi

Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Compiling a model with cygwin or Rtools?

Post by tomfid »

First delete the MDL.BAT file that you copied to the model folder, it will not get called.
The mdl.bat that gets used is the one in the Compiled Simulation path, which you set via Tools>Options>Startup.

Also, be aware that there are 2 batch files: mdl.bat for single precision and mdldp.bat for double precision.
billh
Member
Posts: 45
Joined: Tue Jan 10, 2017 11:48 pm
Vensim version: DSS

Re: Compiling a model with cygwin or Rtools?

Post by billh »

The only path set right now on my system is the Molecule library path.

Does this mean that I store a .vmf file in c:\Users\Public\Vensim\comp (W7), put mdl.bat there, and find the compiled result there? But the .mdl file stays in its current directory?

I guess I'm confused. It should get easier, I'm sure, when I have one done.
Last edited by billh on Thu Oct 12, 2017 8:25 pm, edited 1 time in total.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Compiling a model with cygwin or Rtools?

Post by tomfid »

The only thing set right now on my system is the Molecule library path.
You'll need to set the Compiled Simulation path, via Tools>Options>Startup. Typically it points to c:\users\public\vensim\comp.
Does this mean that I store a .vmf file in c:\Users\Public\Vensim\comp (W7), put mdl.bat there, and find the compiled result there? But the .mdl file stays in its current directory?
No. The model stays in your project folder, wherever that is. When you run compiled, Vensim generates a .c file from the model, then uses mdl.bat (where you pointed to it) to direct the compiler to create modelname_sim.dll (in the model folder) and links to that.
Post Reply