Git 解决gcc中未定义引用库链接错误

Git 解决gcc中未定义引用库链接错误,git,gcc,build,linker,shared-libraries,Git,Gcc,Build,Linker,Shared Libraries,我试图构建git的第一个提交,即提交e83c516 我所面临的是一个链接器错误,如下所示 $ make gcc -g -Wall -o update-cache update-cache.o read-cache.o -lssl

我试图构建git的第一个提交,即提交e83c516 我所面临的是一个链接器错误,如下所示

$ 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)
因此,这其中存在一些链接器错误。我试着寻找它,用上面的错误信息搜索了几个地方,但运气不好。主要是stackoverflow的链接不多。 我在下面解释我理解它的过程。

我阅读了解释库链接。我建议任何面临类似问题的人先读一读

因此,我将帮助新用户解析错误消息。问题是它无法找到加密库。因此,我们需要首先链接该库

-lcrypto
添加到LIBS库列表中。我怎么知道的。查看错误消息
/usr/bin/ld:update cache.o:对符号'SHA1_Init@@libcrypto.so.10'的未定义引用中缺少的库。
。您需要从libcrypto.so.10中找出加密部分

LIBS= -lssl -lcrypto 
执行此操作后,您会收到类似的错误消息:

/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  
现在你知道该怎么做了。添加
-lz
库。所以最后LIBS看起来像下面的一个

LIBS= -lssl -lcrypto -lz 
这就是解决类似链接器错误的方法(并编译git的第一次提交)

希望这有帮助:)