简体   繁体   English

在Mac Terminal whit Header中编译C文件

[英]Compile a C file in the Mac Terminal whit Header

Sry for my bad english. 我的英语不好。

I want to compile in the mac terminal ac file name: "test.c" and a headerfile name: "mylib.h" . 我想在mac终端ac文件名中编译:“test.c”和头文件名:“mylib.h”。 How i can do it. 我怎么做

Try doing: 尝试做:

gcc test.c -lmylib -o mycompiledtest

This assumes the .h file lives in the same folder as your .c file and if you have a library named " mylib " (for which the mylib.h file exists), you should include it after the -l bit in your gcc line 这假定.h文件与.c文件位于同一文件夹中,如果您有一个名为“ mylib ”的库(mylib.h文件存在),则应在gcc行中的-l位之后包含它

More information about gcc found here . 有关gcc的更多信息,请点击此处

If gcc isn't found for you, try installing from the "command line tools" installer found at the Developer Tools download page (you'll need to sign in with your Apple ID). 如果找不到gcc,请尝试从Developer Tools下载页面上的“命令行工具”安装程序进行安装(您需要使用Apple ID登录)。

See this to know how to compile ac program on your mac: How do I compile a .c file on my Mac? 看看这个知道如何在你的mac上编译ac程序: 如何在我的Mac上编译.c文件? (basically, install GCC). (基本上,安装GCC)。

For including the header file in the same path, #include "mylib.h" should work on GCC. 要将头文件包含在同一路径中,#include“mylib.h”应该适用于GCC。 See this: https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html#SEC6 请参阅: https//gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html#SEC6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM