相关疑难解决方法(0)

使用-fPIC支持编译ghc

我正在尝试在Fedora中安装带有-fPIC支持的GHC.我已经抓住了一个源tarball,因为它似乎没有二进制文件.

在Build.mk中,我已将快速构建类型更改为

ifeq "$(BuildFlavour)" "quick"

SRC_HC_OPTS        = -H64m -O0 -fasm -fPIC
GhcStage1HcOpts    = -O -fasm -fPIC
GhcStage2HcOpts    = -O0 -fasm -fPIC
GhcLibHcOpts       = -O -fasm -fPIC
SplitObjs          = NO
HADDOCK_DOCS       = NO
BUILD_DOCBOOK_HTML = NO
BUILD_DOCBOOK_PS   = NO
BUILD_DOCBOOK_PDF  = NO

endif
Run Code Online (Sandbox Code Playgroud)

不幸的是,在编译时我仍然得到ld错误

ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math
Linking a.out ...
/usr/bin/ld: /tmp/Hs2lib924498/Hs2lib.o: relocation R_X86_64_32 against `ghczmprim_GHCziUnit_Z0T_closure' can not be used when making a shared object; …
Run Code Online (Sandbox Code Playgroud)

haskell ffi static-libraries fpic ghc

22
推荐指数
1
解决办法
1870
查看次数

使用C++中的haskell函数:未定义的引用错误

我想用C++调用haskell函数,并使用http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/ffi-ghc.html上的教程.

所以我有一个haskell文件Foo.hs:

module Foo where

foreign export ccall foo :: Int -> IO Int

foo :: Int -> IO Int
foo n = return (length (f n))

f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
Run Code Online (Sandbox Code Playgroud)

并呼吁

ghc Foo.hs
Run Code Online (Sandbox Code Playgroud)

它创建了一个Foo_stub.h:

#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)

一个Foo_stub.c:

#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
#ifdef __cplusplus
extern "C" {
#endif

extern StgClosure …
Run Code Online (Sandbox Code Playgroud)

c++ haskell g++ ffi ghc

2
推荐指数
1
解决办法
846
查看次数

标签 统计

ffi ×2

ghc ×2

haskell ×2

c++ ×1

fpic ×1

g++ ×1

static-libraries ×1