Search code examples
c++macoscompilationansi-c

Compiling ANSI C++ code on Mac OS X


I'm struggling to compile and run a program on Mac OS X, which is written using ANSI/ISO C++ (Windows). Source code

I've tried to compile using g++, and by importing the files and compiling using Xcode.

If i try to compile using g++ (command line), I get a couple of warning, which are easy to fix,:

e.g. warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’.

But, i get some weird errors as well.

If i create a simple "Command Line Tool" project of Type "C++ stdc++", and import all the files in this project, it gives me a bunch of warnings and an error.

Can anyone please help me compile this sample source code? Thanking in anticipation.


Solution

    • In stopwatch.cpp change the include at line 49 from strstream.h to sstream.
    • In stopwatch.cpp line 50 change the include from fstream.h to fstream.
    • In qsort.h change the declaration of Qsort() so the second and third parameters are unsigned long rather than size_t.
    • In qsort.cpp change the definition of Qsort() so the second and third parameters are unsigned long rather than unsigned.

    As a side note, the declaration and the definition of Qsort() didn't (necessarily) match in signature, and that's incorrect.