I’m trying to separate the QSPICE generated C++ source code with my own code that does the actual logic.
As the example, I have the simulation model “flyback_pfc.qsch”, in which a .dll element “flyback_pfc_X1” whose source code template “flyback_pfc_X1.cpp” is generated automatically. Instead of e.g., including my source code #include "controller.cpp" in “flyback_pfc_X1.cpp”, I would like to know if it is possible to compile “controller.cpp” and “flyback_pfc_X1.cpp” separately, and have two .dll files, so that in the future I may choose to release the “controller.dll” without showing the source code to others.
To make a test and see if it is possible, think I need to know how QSPICE, in a general way-of-working, compiles the .cpp source code to the .dll lib. Can someone help me with that? Great thanks!
I’m assuming that controller.cpp and flyback*.cpp are a single QSpice component. If so, you’d generate the two object files and link them into the single DLL. Command line options are here: Compiling Code - Digital Mars.
I did a bit more investigation. It seems to be pretty straight-forward. The auto-generated code will have something like this in the comments at the top of the *.cpp file:
dmc -mn -WD target.cpp kernel32.lib
where target.cpp is the component code.
Simply insert additional *.cpp files after target.cpp. They will be compiled and linked into target.dll.
Of course, you’ll need to run this from a command line or in a batch file and, if the path to the DMC compiler isn’t in the shell path, add the path to the command. (Default installation is: “C:\Program Files\QSPICE\dm\bin\dmc.exe”.)
So, to compile Target1.cpp and Target2.cpp into Target1.dll from the command line:
The DMC compiler appears to be no longer under development. I finally found a bit that said that it supports C++98. If you want to write code in a more modern version of C++, you can consider MinGW and MS VC. I have a QSpice template that supports all three compilers on my Github repo.