Compile Errors on macOS

Use this forum to post Vensim related questions.
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Compile Errors on macOS

Post by aliakhavan89 »

Hello,

I have been trying to compile a (test) model, but I face an error despite following the steps provided on the tutorial/help page. I will explain the details below, and I have provided the files I have.

The error is: Failed to compile the model (does not exist).

1. OS: macOS Monterey Version 12.6 (2.2 GHz 6-Core Intel Core i7)
2. I installed the gcc compiler using brew.sh (I followed this tutorial: https://www.youtube.com/watch?v=0z-fCNNqfEg)
3. Moved the test model to the comp folder (Users/Shared/Vensim/Comp)
4. I am on Vensim® DSS Version 9.3.x x64 (Intel)
5. I did not change vensim.h and simext.c files

Could you please help me on this?
Attachments
Test_Model.zip
(18.46 KiB) Downloaded 126 times
Screen Shot 2022-09-19 at 11.51.54.jpeg
Screen Shot 2022-09-19 at 11.51.54.jpeg (50.64 KiB) Viewed 16587 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

There is no guarantee that this will work anymore.

Apple only allow dylibs that are signed by the same developer to be loaded by a process (so Vensim would only load a dylib if we digitally signed it ourselves, totally impractical as you would need to send the model to us to compile it). This can be disabled (which we tried), but the requirement for signed dylibs probably still remains. This is why there is no equivalent of the Vensim DLL on the Mac, most software cannot/refuse to load it.

I'd start by using clang (the Apple compiler) rather than gcc. Install Xcode and it's command line tools. Then try compiling. If it compiles, great, if not, you'll need to start a terminal and try compiling the code Vensim generates manually. If it does compile, you will need to figure out how to digitally sign the dylib and try again.
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
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

I could compile the mdl.c manually on Xcode (signing the c file locally might have helped, though I did not test it systematically). Still, Vensim does not automate the process. I would imagine by signing the dylib you meant something like this (I am not asking you to recommend. Just want to know if this could be a potential solution, and I am aware of the challenges):

https://stackoverflow.com/questions/611 ... oper-accou

Before, finding this, I was thinking of a certificate (even untrusted) that can resolve this issue. I do not know if it is in general possible and you would have the resources to do it as an extra package for Vensim.
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Has anything changed with Vensim 10 or macOS? After a year of posting this, I can compile models on Mac without going through the digital signature.

I have installed several applications for other projects, such as Xcode and Command Line Tool, and I am on macOS Sonoma. Also, I have run the mdldp.macx a few times in Terminal, so I cannot tell what has changed that compilation is possible (I have also found some issues when compiling a model with .vdfx as data input, which I will share later). If someone helps me by reproducing the errors, I can post the steps I have taken to compile models on macOS successfully. I will report the data issue (I assume), too.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

Nothing has changed with Vensim 10.

As I mentioned before, I don't think it will work anymore. Compiling into a dylib is easy, that's not the problem. Getting it to work in Vensim without a valid Ventana digital signature is the problem. There is no way around that as far as I know. Internally, we create a dylib for the spell checker, we could only make it work in Vensim if we digitally sign it with the same certificate as Vensim has. The digital signatures have to match.
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
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Would you please clarify what you mean by "Getting it to work in Vensim without a valid Ventana digital signature is the problem?"

When I compile a model through Terminal, I can run it and optimize it without errors on Vensim (the Compile settings are on). Do you mean the runs I get are just interpretations, not compilations? Without compiling through Terminal and the dylib file, it is not possible, of course.
Travis
Senior Member
Posts: 141
Joined: Tue Jul 15, 2008 8:42 pm

Re: Compile Errors on macOS

Post by Travis »

I'm interested and trying to help... I haven't look at compiling lately so still getting up to speed...

My first question –– and it is likely just outdated documentation –– is that does Vensim expect the dylib to be named? In the "Macx" file the comment suggests that for a model call myModel.mdl the lib should be libmyModel.dylib. In the script that might be $3 but I wanted to check.

Also, I don't see "libtest" anywhere. Should that be in the `comp` directory?

Here is the comment for the record:

[code]
#!/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)
[/code]
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

aliakhavan89 wrote: Fri Sep 29, 2023 2:44 am Would you please clarify what you mean by "Getting it to work in Vensim without a valid Ventana digital signature is the problem?"

When I compile a model through Terminal, I can run it and optimize it without errors on Vensim (the Compile settings are on). Do you mean the runs I get are just interpretations, not compilations? Without compiling through Terminal and the dylib file, it is not possible, of course.
The security on the Mac now prevents an application from loading a dylib unless it has the same signature as the application loading it. Vensim is digitally signed using our developer certificate. So we could compile a model and load it as long as we sign it, but unless we release our developer credentials to the world (which we will not do), it's unlikely a dylib developed by someone else will load.

This is why there is no equivalent of the Vensim DLL for the Mac. Security prevents applications from loading it.
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
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

Travis wrote: Fri Sep 29, 2023 12:10 pm I'm interested and trying to help... I haven't look at compiling lately so still getting up to speed...
If you know a way to get around the security...... That's the problem.
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
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Thank you very much, Travis!

The dylib file that I have in the comp folder is named lib_simdp_x64. 

Let me share the steps I take:

1. Move the Vensim model (model.mdl) to the comp folder.
2. Run (with the compile option turned on) the model in Vensim until you get the error that says 'Failed to Compile' but it generates mdl.c 
3. Open Terminal and change the directory to comp folder
4. Use this command: chmod +x mdldp.macx
5. Then use this command in the terminal: ./mdldp.macx
6. The model should successfully compile 
7. If you go back to Vensim and run again, you will probably get the same error. I have found it useful to completely close Vensim, reopen it, and run the model again (with the compile option turned on). Then, the compilation goes through successfully.

I can record my screen and share it with you all to show what happens on my end. 


This the content of my mdldp.macx:

#!/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 clang --debug -Dunix -arch x86_64 -arch arm64 -DDBLPREC -dynamiclib mdl.c -I "$2" -o "$outf"
else clang --debug -Dunix -arch x86_64 -arch arm64 -DDBLPREC -dynamiclib mdl.c -o $outf
fi
if [ -e "$outf" ]
then echo "Successfully compiled"
else echo "Errors in compiling."
fi
Attachments
Screenshot 2023-09-29 at 09.19.47.jpg
Screenshot 2023-09-29 at 09.19.47.jpg (147.53 KiB) Viewed 16263 times
Screenshot 2023-09-29 at 09.11.48.jpg
Screenshot 2023-09-29 at 09.11.48.jpg (186.47 KiB) Viewed 16263 times
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Could it be that I am running a dylib that I compiled myself (on the same machine that I have the Vensim)? It seems that we cannot distribute dylib files at all (like the issues with Vensim DLL), but we can run the ones we compiled ourselves.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

I don't think you are understanding what I am saying.

Apple security prevents an application from loading a dylib unless it has the same digital signature. You do not have the Ventana developer credentials in order to sign your dylib. That means Vensim will not load it.

You can create all the dylibs you want, there is nothing to stop you doing that. Try and load them into another application and it will probably fail.

Try loading your dylibs into MS Excel via visual basic, you'll see what I mean.

Apple security is the problem, not the creation of dylibs.
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
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

I thought I was clear before. After creating the dylib, I return to Vensim, and the simulation or optimization goes through much faster without any errors. Can you help me understand why this is the case?
Travis
Senior Member
Posts: 141
Joined: Tue Jul 15, 2008 8:42 pm

Re: Compile Errors on macOS

Post by Travis »

[quote=Administrator post_id=32064 time=1695993373 user_id=4547]
[quote=Travis post_id=32062 time=1695989405 user_id=1427]
I'm interested and trying to help... I haven't look at compiling lately so still getting up to speed...
[/quote]

If you know a way to get around the security...... That's the problem.
[/quote]


I understand the issue about Apple security and signing and SIP.

Could you review my question above, though, and confirm what dylib filename vensim is trying to load? Is "libmyModel" being passed as the third argument ($3)?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

If the model is saved as <modelname> and the path is <modelpath>, the actual command Vensim launches is

/Users/Shared/Vensim/comp/mdldp.macx /Users/Shared/Vensim/comp/ "/Users/Shared/Vensim/comp" "<modelpath>/<modelname>_simdp_x64"
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
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

I've attached a zip file with some modified files to place into the comp folder (please backup what you have there first).

These appear to work ok for me on enroads (plus other models).

I'd appreciate it if anyone else could give these a try.
Attachments
comp_modified_files.zip
(15.73 KiB) Downloaded 109 times
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
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

It worked for me after deleting the old mdl.c and dylib I had in that folder.
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Thank you very much for addressing this issue. I tested version 10.1.0 on macOS, and the compilation works as expected.

I also want to report another issue I face running the attached model (the Commodity Cycle). I can normally run (through the interpret option) the model, but using the compilation, I get a floating point error on macOS. I could not replicate this issue on other simplified models, and I confirm that I have no problem compiling the same model on Windows.

I'd appreciate it if you could provide any feedback on this. Once again, thank you very much for addressing the compilation issue.

--------

FYI, a few months ago, we faced an issue when we tried to translate the model to Python using PySD and eventually realized the problem was from a duplicated xy point in the table function: (2,1) was used twice in the table function in the original model.
Attachments
Screenshot 2023-10-03 at 09.36.47.jpg
Screenshot 2023-10-03 at 09.36.47.jpg (293.33 KiB) Viewed 16106 times
Session 7 - Calib.zip
(832.45 KiB) Downloaded 121 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

It runs both interpreted and compiled for me. If you can give me step by step instructions, I can try and re-create the error here.

One note. You don't check for division by zero in
TABLE FOR ORDER FULFILLMENT(maximum shipment rate/desired shipment rate)
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
Travis
Senior Member
Posts: 141
Joined: Tue Jul 15, 2008 8:42 pm

Re: Compile Errors on macOS

Post by Travis »

I get an error saying that the compilation failed because the model file doesn't exist. I opened the MDL file from within Vensim using the File->Open command. I've changed the Options so that running a "Simulation" requires compilation. I start the simulation using the single-run button in the toolbar.

I have already replaced the files in the "comp" folder and deleted an dylibs or mdl.c files that might have been made previously.

This seems like it is failing before before calling clang. What should I try next?

EDIT: I'm not running Vensim 10.1 so I'll try to upgrade...
Travis
Senior Member
Posts: 141
Joined: Tue Jul 15, 2008 8:42 pm

Re: Compile Errors on macOS

Post by Travis »

No, it still doesn't work for me with v10.1. What should I try next?

My "model" and the error message:
[attachment=0]Screenshot 2023-10-03 at 8.16.37 PM.png[/attachment]
Attachments
Screenshot 2023-10-03 at 8.16.37 PM.png
Screenshot 2023-10-03 at 8.16.37 PM.png (290.32 KiB) Viewed 16080 times
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Travis, it happens to me from time to time. I fix it by closing Vensim, removing the related mdl.c and dylib files, opening Vensim, and recompiling again. I mentioned this earlier to the admin after they shared the updated comp files.
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

I reported an error about the floating point error when compiling a model. Here's the steps I take:

https://www.youtube.com/watch?v=mq8tSoV5XMs
aliakhavan89
Senior Member
Posts: 94
Joined: Sun Oct 21, 2018 7:09 am
Vensim version: DSS

Re: Compile Errors on macOS

Post by aliakhavan89 »

Besides the floating point error, why does a new window open when I open a model? I checked with my colleagues, and they had the same issue. It gets frustrating after a while.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Compile Errors on macOS

Post by Administrator »

I'll have to do a new release and make sure the updated files are in the COMP folder. I'm on it.
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
Post Reply