Compile without main() method?

I am using the 64 bit TDM C++ compiler on 64 bit Windows 10 Home edition with great success. I am using Dev-C++ as my IDE.

-If I want to compile my C++ classes in the total absense of a main method, say, for a small library, how can I achieve this? What is the compiler switch option involved?
You can write classes in a separate headerfile and then include them to another program (no main function in headerfile). But the program including the headerfile should have a main function in order for execution.

Execution needs main function. I don't think compiling does. Then again what's harm in using an empty main function?
I had suspected this, and thank you for your reply. If I am using Dev-C++ to program with,
it will compile, link, and build my source code. Is there a way to only compile, with this IDE,
in the absence of a main method, and get past its error warnings and refusal to generate a binary file?
I'm not familiar with Dev-C++, but in most IDE's there's a way to tell the linker to create a library, rather than an executable, in which case no main function is needed. You need to explore your IDE to find out how to do this.

Is there a way to only compile

If you only compile, you will only get a bunch of object files. Is this what you want? Or do you actually want to link these object files together into a library?

Grime wrote:
Then again what's harm in using an empty main function?

The OP has stated they want to create a library. How, exactly, would it be possible to write a program that links against a library that has a main function in it, empty or otherwise?
Last edited on
In the situation where I want to compile a class and build into a .dll file on Windows,
how can I acheive this in the absence of a main method, considering the compiler I am using (see top of thread for that)? Is this even possible?
What is a actually the problem ?
In your IDE go to File->New->Project and choose DLL.
Add your class and write a function to export objects.
If you want you can add a DllMain function.

These might help
https://www.codeproject.com/Articles/28969/%2FArticles%2F28969%2FHowTo-Export-C-classes-from-a-DLL

https://docs.microsoft.com/en-us/windows/desktop/dlls/dllmain

https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-best-practices
I think you need more knowledge about the fact that DLLs does not use main at all, the entry point for them is DllMain.

The entry point DllMain is arbitrary, it can be changed.

main is only for console applications, it can be changed too or not present at all and executable still works fine if you write it in assembler ( no C runtime involved )
Topic archived. No new replies allowed.