How to compile and run C/C++ in a Unix console/Mac terminal?(如何在 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.
您甚至不需要生成文件.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.
运行刚刚构建的可执行文件与运行任何程序相同 - 但您通常需要指定可执行文件的路径,因为 shell 只会搜索 $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++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Unix 控制台/Mac 终端中编译和运行 C/C++?
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
