2

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?

  • 3
    Just use any C++ test framework and write unit tests. You can easily link them against the dll. – pschill Jun 6 at 21:27
  • Welcome to the worlds of unit and integration testing. – whatsisname Jun 6 at 21:37
  • @pschill: your comment sounds like a start for a good answer. – Doc Brown Jun 6 at 21:41
5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.