English 中文(简体)
Haskell 可执行地与C++中写成的静态图书馆链接
原标题:Haskell executable linking with static library written in C++ got `undefined reference`

I. 创建静态图书馆:

// foo.h
extern "C" {
int foo (const char* arg0, int arg1);
}

// foo.cpp
#include "foo.h"
// implementation of foo

该代码编为foo.o,并包装为libfoo.a,安装到MinGW s代码lib dir(在Windows,使用海合会工具链)。

我想做的是,在哈萨克瑟法典中总结这一职能,因此,一个典型的金融基金具有如下约束力:

-- Foo.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Foo where

foreign import ccall "foo"
    c_foo :: CString -> CInt -> IO (CInt)

www.un.org/Depts/DGACM/index_spanish.htm 添加到<代码>。

...
extra-libraries: foo, stdc++

但是,GHC公司对未明确提及foo的同义词:

.dist-scionuildpath	oFoo.o:fake:(.text+0x514): undefined reference to `foo 

nm http://www.un.org 图书馆实际上已经存在(名称有某些缺陷),我在此 st。


[EDIT]
I also tried build the haskell package using cabal:

cabal configure
cabal build

结果表明:

Loading object (dynamic) foo ... ghc.exe: foo: ....
<command line>: user specified .o/.so/.DLL could not be loaded (addDLL: could not load DLL)

因此,这是否应当与静态/动力联系有关? 因此,我注意到GHC希望装载<代码>o/.so/.DL但NOT.a。 我真的混淆不清。


http://www.haskell.org/haskellwiki/Cxx_foreign_Function_interface” rel=“nofollow”职称=“Cxx Foreign Function Interface”


[EDIT]
One solution is to use -optl-lfoo -optl-lstdc++ in .cabal file, not extra-libraries. And the naming problem can be easily solved by wrapping the declaration in extern "C":

#ifdef __cplusplus
extern "C" {
#endif

extern int foo (const char*, int);

#ifdef __cplusplus
}
#endif

在EclipseFP内进行这项工作,因此使用假肢。 但是,它仍然未能在<条码>建造

问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签