GHC 不链接依赖项

GHC not linking dependencies

本文关键字:依赖 链接 GHC      更新时间:2023-10-16

我正在尝试使用Haskell外部函数接口,但我遇到了一些麻烦;也就是说,一旦我尝试使用外部依赖项(在本例中为来自text包的Data.Text(,GHC就无法将我的二进制文件与对包的未定义引用链接起来。我是否做错了什么,或者我需要添加一些标志才能使 GHC 链接依赖?

当我尝试手动将~/.cabal/lib/x86_64-linux-ghc-8.0.1/text-1.2.2.1-9Yh8rJoh8fO2JMLWffT3Qs/libHStext-1.2.2.1-9Yh8rJoh8fO2JMLWffT3Qs.a添加到OBJECTS列表中时,构建仍然失败,缺少对bytestring的引用,这是text的依赖项。

制作文件:

CXX=clang++
CXXFLAGS=-pthread -std=c++1y -g -Wall -Wextra -Wpedantic -Werror #-O2
INCLUDES=-I /usr/lib/ghc/include/
GDB=gdb
LDFLAGS=-lstdc++ -lpthread
LIBRARIES=-lstdc++
GHC=ghc
GHCOPTS=-XForeignFunctionInterface -optl-pthread
OBJECTS= 
 main.o 
 logger.o 
 socket.o 
 queue.o 
 thread.o 
 irc/connection.o 
 irc/message.o 
 hydra/message.o 
 hydra/session.o 
 hydra/server.o 
 hydra/client.o 
 hydra/node.o 
 plugin/manager.o 
 plugin/plugin.o 
 plugin/haskell.o 
 plugin/haskell/Plugin.o 
 plugin/haskell/Message.o
EXECUTABLE=hebi
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
        $(GHC) -o $@ -no-hs-main -optc-O $(OBJECTS) $(LDFLAGS) $(LIBRARIES)
main.o: main.cpp logger.hpp irc/connection.hpp hydra/session.hpp thread.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
logger.hpp: logger.ipp
logger.o: logger.cpp logger.hpp config.hpp thread.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
socket.hpp: socket.ipp
socket.o: socket.cpp socket.hpp config.hpp logger.hpp queue.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
queue.hpp: queue.ipp
queue.o: queue.cpp queue.hpp logger.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
thread.hpp: thread.ipp
thread.o: thread.cpp thread.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
irc/connection.o: irc/connection.cpp irc/connection.hpp config.hpp logger.hpp socket.hpp queue.hpp thread.hpp irc/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
irc/message.o: irc/message.cpp irc/message.hpp config.hpp logger.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
hydra/message.o: hydra/message.cpp hydra/message.hpp config.hpp logger.hpp queue.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
hydra/session.o: hydra/session.cpp hydra/session.hpp config.hpp logger.hpp socket.hpp thread.hpp hydra/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
hydra/server.o: hydra/server.cpp hydra/server.hpp config.hpp logger.hpp socket.hpp thread.hpp hydra/node.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
hydra/client.o: hydra/client.cpp hydra/client.hpp config.hpp logger.hpp socket.hpp thread.hpp hydra/node.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
hydra/node.o: hydra/node.cpp hydra/node.hpp socket.hpp queue.hpp hydra/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
plugin/manager.o: plugin/manager.cpp plugin/manager.hpp plugin/plugin.cpp irc/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
plugin/plugin.o: plugin/plugin.cpp plugin/plugin.hpp irc/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
plugin/haskell.o: plugin/haskell.cpp plugin/haskell.hpp plugin/plugin.cpp plugin/haskell/Plugin_stub.h irc/message.hpp
        $(CXX) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
plugin/haskell/Plugin_stub.h: plugin/haskell/Plugin.o
plugin/haskell/Plugin.o: plugin/haskell/Plugin.hs plugin/haskell/Message.o
        cd plugin/haskell/; $(GHC) -c $(GHCOPTS) -O $(shell basename $<)
plugin/haskell/Message.o: plugin/haskell/Message.hs
        cd plugin/haskell/; $(GHC) -optl-static -O $(shell basename $<)
clean:
        $(RM) $(EXECUTABLE) *.o */*.o */*/*.o

进行输出:

cd plugin/haskell/; ghc -optl-static -O Message.hs
[1 of 1] Compiling Message          ( Message.hs, Message.o )
cd plugin/haskell/; ghc -c -XForeignFunctionInterface -optl-pthread -O Plugin.hs
compilation IS NOT required
ghc -o hebi -no-hs-main -optc-O main.o logger.o socket.o queue.o thread.o irc/connection.o irc/message.o hydra/message.o hydra/session.o hydra/server.o hydra/client.o hydra/node.o plugin/manager.o plugin/plugin.o plugin/haskell.o plugin/haskell/Plugin.o plugin/haskell/Message.o -lstdc++ -lpthread -lstdc++
plugin/haskell/Message.o: In function `r8Ds_info':
(.text+0x2c43): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `c9TW_info':
(.text+0x2d6b): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `c9Ud_info':
(.text+0x2da0): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `c9Sy_info':
(.text+0x2f5c): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `c9Tv_info':
(.text+0x3020): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `c9Tv_info':
(.text+0x3040): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `c9UI_info':
(.text+0x31b3): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `ca18_info':
(.text+0x32db): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `ca1p_info':
(.text+0x3310): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `c9ZK_info':
(.text+0x34cc): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `ca0H_info':
(.text+0x3590): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `ca0H_info':
(.text+0x35b0): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `ca1U_info':
(.text+0x3723): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `ca8i_info':
(.text+0x384b): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `ca8z_info':
(.text+0x3880): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `ca6U_info':
(.text+0x3a3c): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `ca7R_info':
(.text+0x3b00): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `ca7R_info':
(.text+0x3b20): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `ca94_info':
(.text+0x3c93): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `cafs_info':
(.text+0x3dbb): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `cafJ_info':
(.text+0x3df0): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `cae4_info':
(.text+0x3fac): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `caf1_info':
(.text+0x4070): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `caf1_info':
(.text+0x4090): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `s8Qy_info':
(.text+0x41e5): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `s8Rk_info':
(.text+0x43ed): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cakr_info':
(.text+0x44e8): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cakK_info':
(.text+0x45d0): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cavd_info':
(.text+0x547b): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `cazH_info':
(.text+0x55a3): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `cazY_info':
(.text+0x55d8): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `cayj_info':
(.text+0x5794): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cazg_info':
(.text+0x5858): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `cazg_info':
(.text+0x5878): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `caEh_info':
(.text+0x5d43): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `caJD_info':
(.text+0x5e6b): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `caJU_info':
(.text+0x5ea0): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `caIf_info':
(.text+0x605c): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `caJc_info':
(.text+0x6120): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `caJc_info':
(.text+0x6140): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `caOP_info':
(.text+0x6530): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `s8VY_info':
(.text+0x65d5): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cbyh_info':
(.text+0xa241): undefined reference to `_hs_text_memcmp'
plugin/haskell/Message.o: In function `cbAx_info':
(.text+0xa31a): undefined reference to `_hs_text_memcmp'
plugin/haskell/Message.o: In function `cbEJ_info':
(.text+0xa7d1): undefined reference to `_hs_text_memcmp'
plugin/haskell/Message.o: In function `cc8u_info':
(.text+0xc12b): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `ccd2_info':
(.text+0xc253): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `ccdj_info':
(.text+0xc288): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_Text_con_info'
plugin/haskell/Message.o: In function `ccbE_info':
(.text+0xc444): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cccB_info':
(.text+0xc508): undefined reference to `_hs_text_memcpy'
plugin/haskell/Message.o: In function `cccB_info':
(.text+0xc528): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `ccg9_info':
(.text+0xc6c4): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_MArray_con_info'
plugin/haskell/Message.o: In function `cbyh_info':
(.text+0xa25c): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziText_zdfEqTextzuzdczeze_info'
plugin/haskell/Message.o: In function `cbA2_info':
(.text+0xa451): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziText_zdfEqTextzuzdczeze_info'
plugin/haskell/Message.o: In function `cbCB_info':
(.text+0xa539): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziText_pack_info'
plugin/haskell/Message.o: In function `cbFN_info':
(.text+0xa6b5): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziText_zdfEqTextzuzdczeze_info'
plugin/haskell/Message.o: In function `ccgf_info':
(.text+0xc792): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziShow_singletonzu_info'
plugin/haskell/Message.o: In function `ccgf_info':
(.text+0xc7f2): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziShow_singletonzu_info'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x218): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x220): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x518): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziText_pack_closure'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x588): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziInternal_empty_closure'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x590): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziArray_arrayzusizzezuerror_closure'
plugin/haskell/Message.o: In function `S9qx_srt':
(.data.rel.ro+0x5a8): undefined reference to `textzm1zi2zi2zi1zm9Yh8rJoh8fO2JMLWffT3Qs_DataziTextziShow_singletonzu_closure'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
Makefile:32: recipe for target 'hebi' failed
make: *** [hebi] Error 1

链接到 Github

我通过在链接命令中添加-package text来解决此问题。您也可以通过将原始 .hs 文件放在 link 命令中而不是单独构建来解决此问题。