0

I'm trying to link a static library archive file (libx/libx.a) with a C code. The library requires 2 flags (-lx -lpthread). After linking the static library my ultimate goal is to create a shared library. I have the following Make file,

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

After using the make command it produces the following output,

/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

I found similar questions here. But that did not help. Seems like I can't make the link work. Any help with what I'm doing wrong?

I would like to achieve the same result generated by the following command,

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 $(@)
user45698746
  • 305
  • 2
  • 13

1 Answers1

0

It seems that your libx.a is located in libx, yet -L references .libx directory. Anyway, since you reference libx/libx.a directly, you may skip both -L.libx/ -lx and it should link just fine.

raspy
  • 3,995
  • 1
  • 14
  • 18