如何使用终端在Mac OS X上运行的C程序? [英] How to run C program on Mac OS X using Terminal?

查看:684
本文介绍了如何使用终端在Mac OS X上运行的C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来C.这是我的你好,世界!程序。

I am new to C. Here is my "Hello,world!" program.

    #include <stdio.h>

int
main(void)

{
  pintf("Hello, world!\n");
  return 0;
}

我尝试运行使用终端它后,它说:

After I try to run it using Terminal it says:

Last login: Tue Sep  1 23:19:47 on ttys000
/Users/macbook/Desktop/peng/Untitled1
MacBook-Pro-MacBook:~ macbook$ /Users/macbook/Desktop/peng/Untitled1
-bash: /Users/macbook/Desktop/peng/Untitled1: Permission denied
MacBook-Pro-MacBook:~ macbook$ 

为什么?

推荐答案

首先,你需要纠正程序中的错误...之前的#include 删除空格和 pintf 更改为的printf 。然后保存为 program.c

First, you need to correct the errors in your program... remove the spaces before #include and change pintf to printf. Then save it as program.c.

现在你需要的编译器,所以你需要去AppStore上下载并安装 X code 这就是苹果的编译器和开发工具。它看起来是这样的:

Now you need the compiler, so you need to go to AppStore and download and install Xcode which is Apple's compiler and development tools. It looks like this:

在这里输入的形象描述

然后,你需要在终端命令安装命令行工具。这使您可以简单地运行 GCC 作为下一行,而不必火了名为 X code中的大,丑陋的软件开发GUI

Then you need to install the command-line tools with this command in Terminal. This allows you to simply run gcc as in the next line without having to fire up the big, ugly software development GUI called Xcode:

xcode-select --install

然后就可以编译code以

Then you can compile your code with

gcc -o program program.c

然后,你可以用它运行

Then you can run it with

./program
Hello, world!

这篇关于如何使用终端在Mac OS X上运行的C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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