Compiling ANSI C++ code on Mac OS X [closed]

2019-09-19 12:04发布

问题:

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.

回答1:

  • 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.



回答2:

In qsort.cpp change the function decleration to:

 52 void __cdecl Qsort (
 53     void *base,
 54     unsigned long num,
 55     unsigned long width,
 56     int (__cdecl *comp)(const void *, const void *)
 57     )

So we just added long to numand widthvariables.

You will also have to fix simple problems like #include <strstream.h>-> #include <strsream>