简体   繁体   English

Makefile:链接。*一个库

[英]Makefile: Linking .*a library

DESCRIPTION: I have a library libshell.a, inside of it is the function ord_interna that i'm attempting to use, however it seems i linked it wrong, could you guys fix my error, so i dont make it in the future? 描述:我有一个库libshel​​l.a,里面是我试图使用的函数ord_interna,但是看起来我把它错了,你们可以解决我的错误,所以我将来不会这样做吗? Cheers, 干杯,

Error: 错误:

/tmp/ccn5lbmJ.o: In function `main':
minishell.c:(.text+0x4e): undefined reference to `ord_interna'
collect2: error: ld returned 1 exit status
make: *** [minishell.o] Error 1

Makefile: Makefile文件:

CC=gcc 
CFLAGS=-Wall -pedantic -c

all: microshell

microshell: minishell.o
    gcc minishell.o -o microshell

minishell.o: minishell.c
    gcc minishell.c minishell.h entrada_minishell.c entrada_minishell.h ejecutar.c ejecutar.h libshell.a

clean:
    rm -rf *o microshell

From your makefile, I'm guessing you have these source files: 从你的makefile,我猜你有这些源文件:

minishell.c
entrada_minishell.c
ejecutar.c

And that you want to compile them, and then link them all together with libshell.a to create an executable called microshell . 而且要编译它们,然后将它们全部用连接在一起libshell.a创建一个名为可执行microshell In that case, you want something like: 在这种情况下,你需要这样的东西:

CC=gcc
CFLAGS=-Wall -pedantic

all: microshell

microshell: minishell.o entrada_minishell.o ejecutar.o
    $(CC) -o $@ $^ -L. -lshell

You can add a clean target if you want, but just that should get you going. 如果你愿意,你可以添加一个clean目标,但这样才能让你前进。

Editorial notes: 编者注:

  1. it's really weird to put header files on the compilation line; 将头文件放在编译行上真的很奇怪; I assumed you didn't actually want to do that. 我以为你实际上并不想这样做。

  2. You should look into gcc's -MMD flag to do automatic dependency generation. 您应该查看gcc的-MMD标志来进行自动依赖关系生成。

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

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