缺什么在我的makefile文件? [英] What is missing in my makefile?

查看:77
本文介绍了缺什么在我的makefile文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建我的第一个Makefile文件。我用下面的命令测试我的程序:

 命令1:GCC -Wall -std -ggdb3 C99 = -o文件1 file1.c中-lm -lpthread -l
命令2:GCC -Wall -std -ggdb3 C99 = -o文件2 file2.c中-lm -lpthread

一切的伟大工程。然后,我创建了一个Makefile文件(请参见下文)。我不断收到错误消息。有人可以看看我的code和给我一个提示的问题是什么?

  file2.o:在功能`seed_primes:
。file2.c中:(文字+ 0x461):未定义引用'开方'
。file2.c中:(文字+ 0x466):未定义引用'开方'
。文件2 :(文字+ 0x533):未定义引用'开方'
file2.o:在功能`create_threads:
。file2.c中:(文字+ 0x668):未定义的参考`pthread_create的
。file2.c中:(文字+ 0x6b5):未定义的参考`在pthread_join
file2.o:在功能`next_seed:
。file2.c中:(文字+ 0x860):未定义引用'开方'
collect2:劳工处返回1退出状态
使:*** [文件2]错误1

下面是我的makefile:

  CC = GCC
DEBUG = -ggdb3
CFLAGS =#(调试)-Wall -lm -lpthread -lrt -lprogs的=文件1文件2所有:$(progs的)文件1:file1.o
    $(CC)$(CFLAGS)-o文件1 file1.ofile1.o:file1.c中
    $(CC)$(CFLAGS)-c file1.c中文件2:file2.o
    $(CC)$(CFLAGS)-o文件2 file2.ofile2.o:file2.c中
    $(CC)$(CFLAGS)-c file2.c中清洁:
    RM -f $(progs的)* *的.o〜


解决方案

您已经设置CFLAGS来,因为注释字符的空字符串(你可能打算使用 $ 来代替)。

您不应该设置成库 CFLAGS ;他们属于在 LDLIBS

您不需要文件1 规则中,文件2 规则,或目标文件的规则。

  CC = GCC
DEBUG = -ggdb3
CFLAGS = $(DEBUG)-Wall
LDLIBS = -lm -lpthread -lrt -lprogs的=文件1文件2所有:$(progs的)清洁:
    RM -f $(progs的)* *的.o〜

注: LDLIBS 及相关 LDFLAGS 的变种不是100%的均匀让 LDFLAGS 应该用于库路径; LDLIBS 是库名(-lxyz 等)。

如果您需要两个程序不同的库,你需要创建单独的生成规则(如你原本),或使用条件宏分配(GNU 制作

I am trying to create my first makefile. I tested my program by using the following commands:

Command 1: gcc -Wall -ggdb3 -std=c99 -o file1 file1.c -lm -lpthread -l
Command 2: gcc -Wall -ggdb3 -std=c99 -o file2 file2.c -lm -lpthread

Everything works great. Then I created a makefile (please see below). I keep getting an error message. Can someone take a look at my code and give me a hint on what the problem is?

file2.o: In function `seed_primes':
file2.c:(.text+0x461): undefined reference to `sqrt'
file2.c:(.text+0x466): undefined reference to `sqrt'
file2:(.text+0x533): undefined reference to `sqrt'
file2.o: In function `create_threads':
file2.c:(.text+0x668): undefined reference to `pthread_create'
file2.c:(.text+0x6b5): undefined reference to `pthread_join'
file2.o: In function `next_seed':
file2.c:(.text+0x860): undefined reference to `sqrt'
collect2: ld returned 1 exit status
make: *** [file2] Error 1

Here is my makefile:

CC=gcc
DEBUG=-ggdb3
CFLAGS=#(DEBUG) -Wall -lm -lpthread -lrt -l

PROGS=file1 file2 

all: $(PROGS) 

file1: file1.o
    $(CC) $(CFLAGS) -o file1 file1.o 

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

file2: file2.o
    $(CC) $(CFLAGS) -o file2 file2.o 

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

clean:
    rm -f $(PROGS) *.o *~

解决方案

You've set CFLAGS to an empty string because of the # comment character (you probably intended to use a $ instead).

You should not set libraries into CFLAGS; they belong in LDLIBS.

You don't need the file1: rule, the file2: rule, or the object file rules.

CC     = gcc
DEBUG  = -ggdb3
CFLAGS = $(DEBUG) -Wall
LDLIBS = -lm -lpthread -lrt -l

PROGS  = file1 file2 

all: $(PROGS) 

clean:
    rm -f $(PROGS) *.o *~

NB: LDLIBS and the related LDFLAGS are not 100% uniform across variants of make. LDFLAGS should be used for library paths; LDLIBS is for the library names (-lxyz etc).

If you need different libraries for the two programs, you will need to create separate build rules (as you had originally), or use conditional macro assignments (GNU make).

这篇关于缺什么在我的makefile文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆