在Mac OS X上编译ANSI C ++代码 [英] Compiling ANSI C++ code on Mac OS X

查看:147
本文介绍了在Mac OS X上编译ANSI C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在Mac OS X上编译和运行程序,这是使用ANSI / ISO C ++(Windows)编写的。 源代码

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

我试图使用g ++编译,通过导入文件和使用Xcode编译。

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

如果我尝试使用g ++(命令行)编译,我得到一些警告,很容易修复:

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


例如警告:格式'%d'期望类型为'int',但参数2具有类型'long unsigned int'

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

$

如果我创建了一个简单的命令行工具类型C + stdc ++,并导入这个项目中的所有文件,它给我一堆警告和一个错误。

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.

推荐答案


  • 在stopwatch.cpp中,将第49行的include改为strstream.h to sstream。

  • 在stopwatch.cpp第50行将include从fstream.h更改为fstream。

  • 在qsort.h中, code> Qsort()所以第二个和第三个参数是 unsigned long ,而不是 size_t

  • 在qsort.cpp中更改 Qsort()的定义,因此第二个和第三个参数为 unsigned long ,而不是 unsigned

    • 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.
    • 作为注释, Qsort()的声明和定义没有(必然)在签名中匹配,并且不正确。

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

      这篇关于在Mac OS X上编译ANSI C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆