cross platform software example c++

Hello,

I am looking to create a small cross platform software using only c++ and i have no clue how to do it.
I tried to google it but all i can find is suggestions about using Qt, boost etc etc which i cannot use.

So can anyone provide me a small code example which can run on both Windows and Mac

I tried referring to Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications
but it seems to be very complex. i mean it talks about design patterns and other high level stuff but nothing to begin .... Like i want a starting point - a kind of template that is a basic structure to use, basic includes to use when developing a cross platform software.
Like i need a starting point.
Any help will be highly appreciated
I am not an expert on this but i have done some cross platform programming so here is what I learned. First, use only standard c++ and stay away from any commands that are specific to one compiler. Second, do not use any stuff that obviously depends on the OS, like system calls or using the windows API. Third, use some kind of automated build system like CMake, so that people can make projects and solutions on different systems. Fourth, use only libraries that are in standard c++ and that are known to work on all your target platforms.
Also I found it helpful to try out if the program works on other OS'es on a regular basis-not when finished writing the code but during the development process.I used a virtual machine for that.
I hope this helps.
Why do you say you cannot use boost or Qt ??


@ljs: i cannot use boost or Qt because that is my project requirement to only use basic standard c++ and no other stuff available in the market.

And thanks a lot for all the guidance but the main problem i am facing right now is that i don't know where to start from. Like i found some code from stack overflow but it didn't work.....Here it is
http://stackoverflow.com/questions/3627127/writing-cross-platform-c-code-windows-linux-and-mac-osx

So i need a basic starting point like a template which works on windows and Mac. Putting different classes and functions or some complex functionality is a later thing

e.g: maybe a program to add two integers which works on both windows and Mac.

If you can help me with that it will really really helpful
actually I think that in the measure in which it is possible, you should try to avoid constructions like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
#ifdef TARGET_OS_MAC
  // Mac Includes Here
#endif

#ifdef __linux__
  // Linux Includes Here
  #error Can't be compiled on Linux yet
#endif

#ifdef _WIN32 || _WIN64
  // Windows Includes Here
  #error Can't be compiled on Windows yet
#endif 


because it limits the number of platforms on which you can build. There is a limited number of functions which require you using these preporcessor commands (like "sleep" on windows which is "usleep" on linux), but it is much better if you can avoid them so that you donĀ“t need these "ifdef"'s.
I will see if I have time later this day to post you the example you want.
As long as you only use standard C++ and don't make assumptions about things that are implementation defined like the size of types, endianness, etc. it should work everywhere.
Stick to the standard and you'll be fine most of the time. Of course you'll need to compile it on each platform you plan on distributing to also.
babbarbhangoo wrote:
I tried referring to Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications but it seems to be very complex. i mean it talks about design patterns and other high level stuff but nothing to begin .... Like i want a starting point


I would have thought that "Item 2: Code from a Common Codebase" would have made a good starting point. It gives you the basics of what you will need to be doing.
Thanks for all the info everyone. Really really appreciate it.

I have another question
Is it possible to create one setup file to be used for both Windows and Mac OS??
Topic archived. No new replies allowed.