简体   繁体   中英

Linking error with openssl-1.1.0c

I'm using Ubuntu 16.10 and it uses openssl in the version 1.0.2g. I've downloaded the latest source-code openssl-1.1.0c from the website and compiled it, which worked fined. Now I've downloaded a example code and tried to compile it, but I've got a linking error.

rm -f  ./cert.o
gcc    -c -o cert.o cert.c
gcc -Wall -g -fPIC -I../../libraries/c/openssl-1.1.0c/include/openssl      -o cert  ./cert.o ../../libraries/c/openssl-1.1.0c/libssl.a     ../../libraries/c/openssl-1.1.0c/libcrypto.a -lpthread  -ldl
./cert.o: In Funktion `main':
cert.c:(.text+0x48d): Nicht definierter Verweis auf `sk_new_null'
cert.c:(.text+0x4d4): Nicht definierter Verweis auf `sk_push'
cert.c:(.text+0x74e): Nicht definierter Verweis auf `sk_free'
collect2: error: ld returned 1 exit status
Makefile:13: die Regel für Ziel „cert“ scheiterte
make: *** [cert] Fehler 1

Makefile:

appname := cert

CC := gcc
CCFLAGS := -Wall -g -fPIC -I../../libraries/c/openssl-1.1.0c/include/openssl
LDLIBS := ../../libraries/c/openssl-1.1.0c/libssl.a ../../libraries/c/openssl-1.1.0c/libcrypto.a -lpthread  -ldl

srcfiles := $(shell find . -maxdepth 1 -name "*.c")
objects  := $(patsubst %.c, %.o, $(srcfiles))

all: clean $(appname)

$(appname): $(objects)
    $(CC) $(CCFLAGS) $(LDFLAGS) -o $(appname) $(objects) $(LDLIBS)

clean:
    rm -f $(objects)

So i've looked for "sk_new_null" found it in "/usr/include/openssl/stack.h". In openssl-1.1.0c it were renamed to "OPENSSL_sk_new_null".

I think, it looks for the wrong header-files. I'm a noob in C, how do I've change the Makefile?

I've changed the wrong paths, but with almost no effect, there were also missing references. It seems that it used some of the openssl-headers in "/usr/include".

But I learned a big lesson, use "make install". I've configured openssl-1.1.0c with an prefix path to "../../libraries/c/usr". With nanomsg I did the same.

Then I add "-I../../libraries/c/usr/include" and "-L../../libraries/c/usr/lib" to the CFLAGS. It works. I can link statically and dynamically to these libraries and it use the correct header-files.

I will always install it by now to an relative path and point to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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