如何在Unix控制台/Mac终端中编译和运行C/C ++? [英] How to compile and run C/C++ in a Unix console/Mac terminal?

查看:211
本文介绍了如何在Unix控制台/Mac终端中编译和运行C/C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Unix控制台或Mac终端中编译/运行C或C ++?

How can I compile/run C or C++ in Unix console or a Mac terminal?

(我知道,忘记了,然后重新学习.请写下来.)

(I know it, forget it, and relearn it again. Time to write it down.)

推荐答案

如果它是一个简单的单一源程序:

If it is a simple single source program:

make foo

其中源文件是foo.c或foo.cpp等.

where the source file is foo.c or foo.cpp, etc.

您甚至不需要makefile. Make具有足够的内置规则,可将您的源文件构建为具有相同名称(减去扩展名)的可执行文件.

You dont even need a makefile. Make has enough built-in rules to build your source file into an executable of the same name, minus extension.

运行刚刚构建的可执行文件与运行任何程序相同-但是您将最需要指定可执行文件的路径,因为外壳程序将仅搜索$PATH中的内容以查找可执行文件,并且大多数情况下会执行此操作.不包括当前目录(.).

Running the executable just built is the same as running any program - but you will most often need to specify the path to the executable as the shell will only search what is in $PATH to find executables, and most often that does not include the current directory (.).

因此要运行构建的可执行文件foo:

So to run the built executable foo:

./foo

这篇关于如何在Unix控制台/Mac终端中编译和运行C/C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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