Question
Is it ok for a C++ Library to have the auto-generated main() function, since the main() is not in the Header file that is distributed with it?
If it is not ok, then would it be better to wrap an #ifdef _DEBUG around main()?
Scenario
I have a C++ Visual Studio project that wraps all our message queue functionality to abstract whatever AMQP we are currently using, and it is compiled as a Library in the Release configuration.
In the Debug Configuration, it is compiled as an executable so that some tests can be ran on it to confirm that it is working.
I have been looking around all morning and can't find any references to what is considered best-practice in this regard.
The idea is that the only part of the library that is used is the put() and get() from the MessageQueue class that is in the library.
I would just refactor the test piece and your problem goes away: Always build your code as a library with no
main
function at all and have a totally separate project that links to the library and does the tests. That way it's built in a way completely similar to actual release use rather than as a self-contained binary executable that's not the same set of circumstances as a normal release usage.