在 Mac 终端中编译一个 C 文件 Header

Compile a C file in the Mac Terminal whit Header

抱歉我的英语不好。

我想在mac终端编译一个c文件名:"test.c" 和头文件名: "mylib.h" 。我该怎么做。

尝试做:

gcc test.c -lmylib -o mycompiledtest

假设 .h 文件与 .c 文件位于同一文件夹中,并且如果您有一个名为“mylib”的库(mylib.h 文件存在),您应该在 gcc

-l 位之后包含它

More information about gcc found here.

如果找不到适合您的 gcc,请尝试从 Developer Tools download page 中的 "command line tools" 安装程序进行安装(您需要使用您的 Apple ID 登录)。

查看此内容以了解如何在 mac 上编译 c 程序: How do I compile a .c file on my Mac? (基本上,安装 GCC)。

为了在同一路径中包含头文件,#include "mylib.h" 应该适用于 GCC。看到这个:https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html#SEC6