How to link custom object file with Haskell library?

孤街浪徒 提交于 2019-12-03 09:33:00

I do a similar thing. I have a Haskell file which calls CUDA code.

Here's how I compile CUDA libraries and link with Haskell:

$(NVCC) -c -E  $(NVCC_OPTS) -o build/file.i file.cu
$(NVCC) -c  $(NVCC_OPTS) -o build/file.o file.cu

I then link everything into a C++ Shared Library called LibSO with Haskell options

$(CXX) -shared -Wl,-rpath=\$$$$ORIGIN $(CXX_LINK_LIBS) $(PACKAGE_RPATH) -Lbuild -rdynamic -L/usr/local/lib/ghc-7.6.3 -lHSrts-ghc7.6.3 -o build/LibSO.so build/file.o

where

CXX_LINK_LIBS = -Lbuild -lcudart -lcuda -lpthread -lcupti -lcurand -lnvidia-ml
NVCC_OPTS = --compiler-options -fPIC -maxrregcount=0 --machine 64 --DCUDA

I then take my Haskell files and compile them into o and hi files. (I compile twice because of TemplateHaskell)

ghc -v0 -Wall -rtsopts -threaded -stubdir build -ibuild/ -no-hs-main  -o build/iop.o -ohi build/iop.hi -c haskell/iop.lhs
ghc -v0 -Wall -rtsopts -threaded -stubdir build -ibuild/ -no-hs-main  -fPIC -dynamic -osuf dyn_o -hisuf dyn_hi -o build/iop.dyn_o -ohi build/iop.dyn_hi -c haskell/iop.lhs

So now we have haskell dynamic objects and a C++ shared library. In the end, I link a main haskell file with everything:

ghc -optl "-Wl,-rpath=\$$ORIGIN" $(CXX_LINK_LIBS) -Lbuild -rtsopts -threaded -lstdc++ -lLibSO -o build/Main build/iop.dyn_o

Does this sort of help?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!