简体   繁体   English

UNIX - makefile帮助!

[英]UNIX - makefile help!

Looking for help compiling my program below. 寻求帮助编译我的程序如下。 I'm getting a "***Stop. no Targets." 我得到了“***停止。没有目标。” error when typing in limit.makefile in the compiler buffer. 在编译器缓冲区中键入limit.makefile时出错。 Ideas? 想法?

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);
  }


}

Compile command: make -k -f limit.makefile This is what I type for the compiler buffer....still get the error though. 编译命令: make -k -f limit.makefile这是我为编译器缓冲区键入的内容....但仍然会收到错误。

Makefile: Makefile文件:

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

Just tried that make -k -f myfile on an empty file and got your error. 刚刚尝试在空文件上制作-k -f myfile并得到错误。

If you just want it to work 如果你只是想让它发挥作用

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



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

Note that the tab under all has to be a "real" tab. 请注意,all下的选项卡必须是“真实”选项卡。

I recommend you check out a makefile tutorial or just compile it from the command line. 我建议你查看一个makefile教程或者只是从命令行编译它。 gcc -g -Wall -std=c99 -O2 -arch x86_64 limit.c gcc -g -Wall -std = c99 -O2 -arch x86_64 limit.c

BTW, not sure about that -arch flag. BTW,不确定那个-arch标志。 Not valid on my Linux box. 在我的Linux机器上无效。

Try 尝试

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

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

EboMike's is more sophisticated, but here's a simpler one that is guaranteed to work for your one-file project: EboMike更复杂,但这是一个更简单的保证适用于您的单文件项目:

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

limit: limit.c
    $(CC) $(CFLAGS) -o limit limit.c

You can run this with just make by itself. 你可以单独使用make来运行它。

You've not defined what the target to build is anywhere. 您还没有定义要构建的目标是什么。 You can do that on the command line, using the command 您可以使用命令在命令行上执行此操作

make -k -f limit.makefile limit

and the implicit rules of make will compile limit.c into limit . make的隐式规则将limit.c编译为limit Alternatively define a target in your makefile, 或者在makefile中定义一个目标,

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

The first target will be built by default, and make knows how to compile *.c to *.o and link object files so everything else is automatic. 第一个目标将默认构建,并且make知道如何将*.c编译为*.o并链接目标文件,以便其他所有内容都是自动的。

If you're curious, the default rules are equivalent to (in GNU make) 如果你很好奇,默认规则相当于(在GNU make中)

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

where $@ , $< and $^ expand to the target, first prereq and all prereqs respectively, the percent signs are wildcards for the target name. 其中$@$<$^扩展到目标,第一个先决条件和所有先决条件,百分号是目标名称的通配符。

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

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