Solution of undefined link to link linking error in gcc

I tried to create the first git ie commit e83c516 commit I encountered a linker error as shown below.

$ make gcc -g -Wall -o update-cache update-cache.o read-cache.o -lssl /usr/bin/ld: update-cache.o: undefined reference to symbol ' SHA1_Init@ @libcrypto.so.10' /usr/bin/ld: note: ' SHA1_Init@ @libcrypto.so.10' is defined in DSO /lib64/libcrypto.so.10 so try adding it to the linker command line /lib64/libcrypto.so.10: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status make: *** [update-cache] Error 1 $ cat Makefile CFLAGS=-g -Wall CC=gcc PROG=update-cache show-diff init-db write-tree read-tree commit-tree cat-file all: $(PROG) install: $(PROG) install $(PROG) $(HOME)/bin/ LIBS= -lssl init-db: init-db.o update-cache: update-cache.o read-cache.o $(CC) $(CFLAGS) -o update-cache update-cache.o read-cache.o $(LIBS) show-diff: show-diff.o read-cache.o $(CC) $(CFLAGS) -o show-diff show-diff.o read-cache.o $(LIBS) 

So there are some linker errors in this. I tried to find it, searched a few places to figure it out using the error message above, with little luck. Basically there were not many stackoverflow links that helped. I explain the process that I did to understand this below.

+5
source share
1 answer

I read this really good post explaining the library linking me. I would suggest everyone who has encountered a similar problem to read it first.

Therefore, I will help the new user analyze the error message. The problem is that he cannot find the crypto library. Therefore, we need to link this library first.

You add -lcrypto to the LIBS library list. As I understand it. Look at the missing library in the error message /usr/bin/ld: update-cache.o: undefined reference to symbol ' SHA1_Init@ @libcrypto.so.10' . You need to find out the cryptographic part from libcrypto.so.10

 LIBS= -lssl -lcrypto 

After that, you will get a similar error message:

 /usr/bin/ld: update-cache.o: undefined reference to symbol 'deflate' /usr/bin/ld: note: 'deflate' is defined in DSO /lib64/libz.so.1 so try adding it to the linker command line /lib64/libz.so.1: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status 

Now you know what to do. Add the -lz library. So finally LIBS looks like below

 LIBS= -lssl -lcrypto -lz 

The way you solve such linker errors (and compile the first git commit).

Hope this helps :)

+9
source

Source: https://habr.com/ru/post/1207718/


All Articles