Page 1 of 1

Compiling a model with cygwin or Rtools?

Posted: Wed Oct 11, 2017 6:11 pm
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.

Re: Compiling a model with cygwin or Rtools?

Posted: Wed Oct 11, 2017 8:57 pm
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


Re: Compiling a model with cygwin or Rtools?

Posted: Wed Oct 11, 2017 9:21 pm
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.

Re: Compiling a model with cygwin or Rtools?

Posted: Thu Oct 12, 2017 7:49 pm
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.

Re: Compiling a model with cygwin or Rtools?

Posted: Thu Oct 12, 2017 8:24 pm
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.