Why always "main.cpp" for MacOS

Hey everyone, I was wondering why I have to call the script “main.cpp” as a MacOS user. It is not a problem, however I am curious as to why that is. Is it something that has to do with VSC or is it more general (e.g. is a system wide requirement, or C++ compatibility on Mac)?

1 Like

The requirement to name the main file “main.cpp” is not a system-wide requirement or specific to macOS. It’s a convention often used in programming, especially with C++ projects. Naming the main file “main.cpp” is a convention that makes it clear where the program starts, as the main function is the entry point for execution.

This convention is not enforced by macOS or Visual Studio Code (VSC). You could name your main file differently, but using “main.cpp” is a widely accepted practice for clarity in C++ projects. It’s not a strict rule, but it helps other developers quickly identify where the program execution begins.

Hope this helps!

1 Like

You are right, I tried naming it something else and it did indeed still run. Makes me wonder why the lecturer always instructed MacOS users to name the script “main.cpp” (instead of what he was naming it on Windows) because otherwise “it will not work”. Perhaps that was the case on an outdated version?

1 Like

That is an interesting point, I use windows and when I worked with c++ I did main just because it felt normal. In fact for a long time I did think it was required to be named as such.

I do get the feeling that the instructors make it seem mandatory just to engrave good habits in your head as naming main something else would seem kinda odd.

Since I use windows, I did a bit of research on Mac and found, the naming conventions for methods, including the entry point method like Main, are consistent across different operating systems when working with C# programming language. Whether you’re developing on Windows or macOS, the naming conventions remain the same for C# code.

However, in other aspects of development, such as file and directory naming, there might be differences in case sensitivity and allowed characters based on the underlying file system (e.g., NTFS on Windows and HFS+ or APFS on macOS). It’s good practice to follow platform-independent naming conventions to ensure your code works seamlessly across different operating systems.

Hopefully this helps a little!

1 Like

At one point, an early version of the template project was specifically looking for a file named “main.cpp” when making builds. That was changed at some point but the course wasn’t updated to reflect that.

That said, I agree that it’s still good practice to name the cpp file that contains the main function “main.cpp”. Especially for larger projects that deal with multiple cpp files (like the last section will)


That’s very good advice, thank you for your input!

1 Like

Ahh that makes sense, thank you very much for clearing that up!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms