Makefile 如何将存档文件与C代码链接?
我试图用C代码链接一个静态库归档文件(libx/libx.a)。该库需要2个标志(-lx-lpthread)。链接静态库之后,我的最终目标是创建一个共享库。我有以下文件Makefile 如何将存档文件与C代码链接?,makefile,gnu-make,Makefile,Gnu Make,我试图用C代码链接一个静态库归档文件(libx/libx.a)。该库需要2个标志(-lx-lpthread)。链接静态库之后,我的最终目标是创建一个共享库。我有以下文件 rsa-engine: rsa/rsa.c rsa/bignum.c rsa/aes.c rsa/x509parse.c rsa/pem.c gcc -fPIC -o rsa/rsa.o -c rsa/rsa.c gcc -fPIC -o rsa/bignum.o -c rsa/bignum.c
rsa-engine: rsa/rsa.c rsa/bignum.c rsa/aes.c rsa/x509parse.c rsa/pem.c
gcc -fPIC -o rsa/rsa.o -c rsa/rsa.c
gcc -fPIC -o rsa/bignum.o -c rsa/bignum.c
gcc -fPIC -o rsa/aes.o -c rsa/aes.c
gcc -fPIC -o rsa/x509parse.o -c rsa/x509parse.c
gcc -fPIC -o rsa/pem.o -c rsa/pem.c
gcc -fPIC rsa-engine.c libx/libx.a -L.libx/ -lx -lpthread -o rsa-engine.o
gcc -shared -o librsa_engine.so -lcrypto rsa-engine.o rsa/rsa.o rsa/bignum.o rsa/aes.o rsa/x509parse.o rsa/pem.o
clean:
rm -f *.o rsa/*.o *.so rsa-engine
使用make命令后,它将生成以下输出:
/usr/bin/ld: cannot find -lx
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'rsa-engine' failed
make: *** [rsa-engine] Error 1
我发现了类似的问题。但这没有帮助。好像我不能让链接正常工作。对我做错的事有什么帮助吗
我希望实现以下命令生成的相同结果
CC := gcc
CFLAGS := -Wall -g -MD -O2 -I ../
LDFLAGS := -lx -lpthread
tests_files := hello
all: $(tests_files)
hello: hello.o ../libx/libx.a
$(CC) $(CFLAGS) -static $(<) -L../libx/ $(LDFLAGS) -o $(@)
CC:=gcc
CFLAGS:=-Wall-g-MD-O2-I/
LDFLAGS:=-lx-lpthread
测试\u文件:=您好
全部:$(测试文件)
你好:你好.o../libx/libx.a
$(CC)$(CFLAGS)-静态$(您的libx.a
似乎位于libx
,但是-L
引用了.libx
目录。无论如何,由于您直接引用了libx/libx.a
,您可以跳过-L.libx/-lx
,链接应该很好