【问题标题】:UNIX - makefile help!UNIX - makefile 帮助!
【发布时间】:2011-05-05 09:50:35
【问题描述】:

在下面寻找编译我的程序的帮助。我得到一个“***停止。没有目标。”在编译器缓冲区中输入 limit.makefile 时出错。想法?

int main(int argc, char *argv[]) {
  struct rlimit limit;

  limit.rlim_cur = 60000;


limit.rlim_max = 60000;

if (setrlimit(RLIMIT_FSIZE, &limit) == -1){
    perror("Error preventing core dump, errno=%d\n", errno);
    exit(1);
  }

else {
    printf("The current core limit is %ll.\n", limit.rlim_cur);
    printf("The core max limit is %ll.\n", limit.rlim_max);
    exit(0);
  }

  if (getrlimit(RLIMIT_FSIZE, &limit) == -1){
    printf("getlimit() failed with errno=%d\n", errno);
    exit(1);
  }


}

编译命令:make -k -f limit.makefile 这是我为编译器缓冲区键入的内容……但仍然出现错误。

生成文件:

CC = /usr/bin/gcc
CFLAGS = -g -Wall -std=c99 -O2 -arch x86_64

【问题讨论】:

  • 你能编辑你的问题并把make limit.makefile放进去吗?
  • 您的 makefile 不包含任何需要编译的文件?
  • limit.c 是我需要的程序。我在哪里添加?

标签: unix compiler-construction makefile system


【解决方案1】:

刚刚在一个空文件上尝试了 make -k -f myfile 并得到了你的错误。

如果你只是想让它工作

CC= /usr/bin/gcc 
CFLAGS = -g -Wall -std=c99 -O2 -arch x86_64



all: test.c
    $(CC) $(CFLAGS) test.c

请注意,所有选项卡下的选项卡必须是“真实”选项卡。

我建议您查看 makefile 教程或直接从命令行编译它。 gcc -g -Wall -std=c99 -O2 -arch x86_64 limit.c

顺便说一句,不确定那个 -arch 标志。在我的 Linux 机器上无效。

【讨论】:

  • -arch 标志适用于 Mac OS X。它允许您显式编译 32 位或 64 位架构。
【解决方案2】:

试试

CC = /usr/bin/gcc
CFLAGS = -g -Wall -std=c99 -O2 -arch x86_64
OBJ = limit.o

%.o: %.c
    $(CC) -c -o $@ $< $(CFLAGS)

【讨论】:

    【解决方案3】:

    EboMike 更复杂,但这里有一个更简单的,可以保证适用于您的单文件项目:

    CC = /usr/bin/gcc
    CFLAGS = -g -Wall -std=c99 -O2 -arch x86_64
    
    limit: limit.c
        $(CC) $(CFLAGS) -o limit limit.c
    

    您可以单独使用 make 运行它。

    【讨论】:

    • 你应该将 $(CFLAGS) 添加到编译器调用中,否则它们将不会被使用
    【解决方案4】:

    您尚未在任何地方定义要构建的目标。您可以在命令行上使用命令

    make -k -f limit.makefile limit
    

    make 的隐含规则会将limit.c 编译成limit。或者在你的 makefile 中定义一个目标,

    CC = /usr/bin/gcc
    CFLAGS = -g -Wall -std=c99 -O2 -arch x86_64
    limit: limit.o
    

    默认情况下会构建第一个目标,并且 make 知道如何将 *.c 编译为 *.o 并链接目标文件,因此其他一切都是自动的。

    如果你好奇,默认规则相当于(在 GNU make 中)

    %.o:%.c
        $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
    %:%.o
        $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    

    其中$@$&lt;$^ 分别扩展为目标、第一个 prereq 和所有 prereq,百分号是目标名称的通配符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 2010-09-21
      • 2011-11-18
      • 1970-01-01
      • 2021-06-22
      • 2015-11-04
      • 1970-01-01
      相关资源
      最近更新 更多