【问题标题】:Compile a C file in the Mac Terminal whit Header在 Mac Terminal whit Header 中编译 C 文件
【发布时间】:2017-01-02 11:07:23
【问题描述】:

对不起我的英语不好。

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

【问题讨论】:

  • "gcc mytest.c"。如果您没有 GCC,请从 App Store 安装 Xcode,然后重试。
  • 这可能很大程度上取决于这些文件中包含的内容。一开始只有一个 .c 和一个 .h 文件是不寻常的。

标签: c macos terminal header-files


【解决方案1】:

尝试做:

gcc test.c -lmylib -o mycompiledtest

这假设 .h 文件与 .c 文件位于同一文件夹中,并且如果您有一个名为“mylib”的库(mylib.h 文件存在),您应该在 @987654325 之后包含它@bit 在你的gcc 行中

More information about gcc found here.

如果没有为您找到 gcc,请尝试从位于 Developer Tools download page 的“命令行工具”安装程序进行安装(您需要使用您的 Apple ID 登录)。

【讨论】:

    【解决方案2】:

    查看此内容以了解如何在您的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      相关资源
      最近更新 更多