Question

I'm developing some C++ code that eventually will be compiled as a DLL to be accessed with Python through CTypes. My workflow is generally that of compiling the DLL and running the Python script which calls the DLL.

However, when rapidly iterating and debugging, that can get cumbersome. Sometimes I want to quickly run the C++ program as an exe with default inputs and just printf some statements. Sometimes I want to see if a method in the C++ code of using a boolean array will work first before going through the process of making sure Ctypes is inputting the boolean array correctly from Python to the DLL first.

Is there a good method of developing a C++ program and quickly being able to switch between compiling it as a DLL and exe? The quickest way I can imagine is keeping a token "main" function that inputs the default variables you want into the function the DLL will access. So if you change the compilation settings to "exe", it will run the main function first.

Is there any better way to do it?

Was it helpful?

Solution

Is there a good method of developing a C++ program and quickly being able to switch between compiling it as a DLL and exe?

A better strategy will be:

  1. Keep the DLL as is.
  2. Create an EXE by linking against the LIB of the DLL. Put all the testing code in the files used to create the EXE.

In a diagrammatic form, you should have:

enter image description here

Licensed under: CC-BY-SA with attribution
scroll top