I am new to C++ from a C#.NET and Visual Studio background (and some Objective-C / XCode).
I want to write cross-platform (Windows, OS X, Linux) application with C++. I started with TextMate on my Mac and Notepad on my Windows, and compile the code using g++ on command line/terminal to build the executables on its platform.
I got confused when I started using IDE (namely VC++, XCode, and Eclipse). I tried all three and created projects before pasting my code in it. If I start editing in one IDE, I do not know how to get the eventual piece of code to compile on different platform.
For example, if I have a class file – foo.cpp. In Eclipse, it would generate foo.cpp (within it a foo.h, foo::foo()) and a separate foo.h header file (within it a FOO_H_ file etc). In Xcode, it generates a folder Foo constains main.cpp and foo.l) – that’s it. Why the difference?
I though C++ code is just C++ code which produce platform specific executables if compiled on that platform. (e.g. compile on Mac, it becomes a Mac executables; if compiled on Windows, it becomes a Windows executables).
It seems, once I started using IDE, my C++ code automatically become unportable, due to all these auto generated files that I have no understanding about. I try reading documentation on XCode, Eclipse, and Visual Studio at the same time, and it confuses me even further. I just want to write C++…
I am also following Stroustrup’s classic text to pick up C++ and in the book, nothing like header or source of .h or _H_ files were mentioned, as of why all these files were generated.
Besides using Notepad/Textmate + G++ compiler, how can I write pure, portable C++ program in an IDE that can be cross-platform, or is it even possible?
The default (=most commonly used) file structure for a c++ class called
Fooconsists of a header file calledfoo.hwhich will contain the class definition ofFoo, and afoo.cppwhich contains the definition of the methods ofFoo.Often all the header files are put into a seperate folder called
include.So the general approach to have the same file/folder structure, which can be used for more than one IDE is:
include,srcandmakefolders inside your project folderMyProject, the project files for IDEs would go into make, .h files into include, and .cpp files into src)