Haskell FFI c2hs链接错误

时间:2013-12-01 12:15:49

标签: c haskell linker ffi

目的和设置

目标:我正在努力使用Haskell FFI来绑定Fastest Fourier Transform in the South library

为此,我选择使用工具c2hs帮助为我编写绑定。我尝试换行的文件名为ffts.h。该文件的核心是以下功能:

#define POSITIVE_SIGN 1
#define NEGATIVE_SIGN -1

struct _ffts_plan_t;
typedef struct _ffts_plan_t ffts_plan_t;

ffts_plan_t *ffts_init_1d(size_t N, int sign);
ffts_plan_t *ffts_init_2d(size_t N1, size_t N2, int sign);
ffts_plan_t *ffts_init_nd(int rank, size_t *Ns, int sign);

// For real transforms, sign == -1 implies a real-to-complex forwards tranform,
// and sign == 1 implies a complex-to-real backwards transform
// The output of a real-to-complex transform is N/2+1 complex numbers, where the
// redundant outputs have been omitted.
ffts_plan_t *ffts_init_1d_real(size_t N, int sign);
ffts_plan_t *ffts_init_2d_real(size_t N1, size_t N2, int sign);
ffts_plan_t *ffts_init_nd_real(int rank, size_t *Ns, int sign);

void ffts_execute(ffts_plan_t * , const void *input, void *output);
void ffts_free(ffts_plan_t *);

正如您所看到的,只有8个函数,一个结构总是由指向它的指针和两个定义引用。很简单。

我为find here的那些函数写了一个包装。然后我used Cabal's configuration以确保正确编译文件。

问题

此时我尝试开始为FFTS库编写HUnit测试用例,以便我可以确保它按预期工作。 但是当我编译代码时,我在链接测试函数TestSuite的最后阶段遇到了以下错误:

Linking dist/dist-sandbox-c6bcbb0c/build/test-fftsStub/test-fftsStub ...
/home/robert/Projects/haffts/dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a(HUnitTests.o): In function `s3l6_info':
(.text+0x418): undefined reference to `testzmfftszm0zi1zi0zi0_FFTS_fftsFree_closure'
/home/robert/Projects/haffts/dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a(HUnitTests.o): In function `s3l3_info':
(.text+0x363): undefined reference to `testzmfftszm0zi1zi0zi0_FFTS_fftsExecute_info'
/home/robert/Projects/haffts/dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a(HUnitTests.o): In function `testzmfftszm0zi1zi0zi0_HUnitTests_hunitTests3_srt':
(.data+0xd0): undefined reference to `testzmfftszm0zi1zi0zi0_FFTS_fftsFree_closure'
/home/robert/Projects/haffts/dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a(HUnitTests.o): In function `testzmfftszm0zi1zi0zi0_HUnitTests_hunitTests3_srt':
(.data+0xd8): undefined reference to `testzmfftszm0zi1zi0zi0_FFTS_fftsExecute_closure'
collect2: ld returned 1 exit status
Failed to install haffts-0.1.0.0

所以这很奇怪。如果这是可信的,则链接器失败,因为它无法找到fftsFree或fftsExecute闭包。所以我决定看看里面:

$ ar t dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a
FFTSTest.o
HUnitTests.o
$ nm dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a | grep fftsFree
                 U testzmfftszm0zi1zi0zi0_FFTS_fftsFree_closure
$ nm dist/dist-sandbox-c6bcbb0c/build/libtest-ffts.a | grep fftsExecute
                 U testzmfftszm0zi1zi0zi0_FFTS_fftsExecute_closure
                 U testzmfftszm0zi1zi0zi0_FFTS_fftsExecute_info
$

现在这似乎表明只有FFTSTest和HUnitTests对象库将其放入存档中,并且fftsFree和fftsExecute函数不存在。 但这很奇怪,因为当我的“Build-depends”包含“haffts”依赖时,它们应该被提供。

此时此刻,我不确定导致此错误的错误。我可以真正使用这个问题的一些帮助和右边的任何建议 方向将不胜感激。

我的问题是:如何修复此错误消息并使其正确链接?

自己重现问题

此外,如果您希望自己重现问题:

git clone https://bitbucket.org/robertmassaioli/haffts.git
cd haffts
git co -b problem-branch 02c5157d149b5ddda56abc83513998bac6966dc3
cabal sandbox init
cabal install --enable-tests

你应该遇到完全相同的问题。

0 个答案:

没有答案