2017-05-27 123 views
2

我想要使用Haskell外部函数接口,并且遇到一些麻烦;即只要我尝试并使用外部依赖项(本例中为text包中的Data.Text),GHC就无法将我的二进制文件与未定义的引用链接到包中。我做错了什么或者是否有一些我需要添加的标志来制作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

的Makefile:

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 [email protected] -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 [email protected] $(CXXFLAGS) 

logger.hpp: logger.ipp 
logger.o: logger.cpp logger.hpp config.hpp thread.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

socket.hpp: socket.ipp 
socket.o: socket.cpp socket.hpp config.hpp logger.hpp queue.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

queue.hpp: queue.ipp 
queue.o: queue.cpp queue.hpp logger.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

thread.hpp: thread.ipp 
thread.o: thread.cpp thread.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(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 [email protected] $(CXXFLAGS) 

irc/message.o: irc/message.cpp irc/message.hpp config.hpp logger.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

hydra/message.o: hydra/message.cpp hydra/message.hpp config.hpp logger.hpp queue.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(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 [email protected] $(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 [email protected] $(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 [email protected] $(CXXFLAGS) 

hydra/node.o: hydra/node.cpp hydra/node.hpp socket.hpp queue.hpp hydra/message.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

plugin/manager.o: plugin/manager.cpp plugin/manager.hpp plugin/plugin.cpp irc/message.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(CXXFLAGS) 

plugin/plugin.o: plugin/plugin.cpp plugin/plugin.hpp irc/message.hpp 
     $(CXX) $(INCLUDES) -c $< -o [email protected] $(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 [email protected] $(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 

Link to Github

回答

2

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