【问题标题】:How to compile C code from other directories in Terminal?如何从终端中的其他目录编译 C 代码?
【发布时间】:2019-02-23 03:04:34
【问题描述】:

当项目组织如下时,我试图弄清楚如何在终端中编译:

 ▼ Practice Exercises
   ▼ example_problems_c
       example_problems_ch1.c
       example_problems_ch2.c
       example_problems_ch3.c
       example_problems_ch4.c

   ▼ example_problems_h
       example_problems_ch1.h
       example_problems_ch2.h
       example_problems_ch3.h
       example_problems_ch4.h

   ▼ example_util_c
       example_conversions.c
       example_lines.c
       example_searches.c

   ▼ example_util_h
       example_conversions.h
       example_lines.h
       example_searches.h

    example_main.c

有人对此有解决方案吗?

【问题讨论】:

  • 终端?就像在 Linux 中一样?如果是 Linux,你可以使用 make 文件来根据这个目录结构来制作你的构建方法。请参阅参考:gnu.org/software/make/manual/make.html
  • 这看起来不像一个项目。相反,它看起来像是针对不同章节或练习的许多单独的资源和标题。您是否需要一次编译一个或一次全部编译它们。如果一下子变成什么? example_main.c?

标签: c terminal


【解决方案1】:

试试

cc -Iexample_problems_h -Iexample_util_h example_problems_c/*.c example_util_c/*.c example_main.c -o name_of_example

如果出现问题,您可能需要添加其他库进行链接,但由于我不知道源代码中的内容,因此无法提供。

此外,此解决方案假定您只有一个 main 函数,大概在 example_main.c 中,并且没有其他重复的函数名称。

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多