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

别来无恙 提交于 2019-12-13 23:11:03

问题


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>



来源:https://stackoverflow.com/questions/4537390/compiling-ansi-c-code-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!