繁体   English   中英

使用GHC 64位构建的普通Windows DLL无法链接

[英]Trivial Windows DLL built with GHC 64-bit does not link

为了进行概念验证,我想将一些琐碎的Haskell代码链接到我的Visual C ++应用程序中(使用Visual Studio 2013)。 使用GHC 7.8.3 32位版本进行构建,但是使用GHC 7.8.4 64位版本进行构建(请注意,GHC版本中也存在细微差异)。

有3个文件: Grep.hsStartEnd.c与GHC一起构建以形成DLL。 main.cpp与Visual Studio 2013一起构建,并尝试在DLL库中进行链接。

我正在从中构建DLL:

> ghc -shared -O -optc-O -o Grep.dll StartEnd.c Grep.hs

从Visual Studio中,我只是链接到Grep.dll.a并包含C:\\Program Files\\MinGHC-7.8.4\\ghc-7.8.4\\lib\\include ,但是链接失败

1>main.obj : error LNK2001: unresolved external symbol _HsEnd
1>main.obj : error LNK2001: unresolved external symbol _freegrep
1>main.obj : error LNK2001: unresolved external symbol _grep
1>main.obj : error LNK2001: unresolved external symbol _HsStart
1>C:\Code\Grep\dist\Win32\Release\Grep.exe : fatal error LNK1120: 4 unresolved externals

当我使用32位而不是64位进行构建时,完全相同的过程起作用。 我可能做错了什么? (尝试链接64位库时,我正在构建64位应用程序。)

源文件:

Grep.hs

{-# LANGUAGE ForeignFunctionInterface #-}

module Grep where

import Foreign
import Foreign.C.String
import Data.List (isInfixOf)

filterlines f = unlines . filter f . lines

grep :: CString -> CString -> IO CString
grep i s = do
    ii <- peekCString i
    ss <- peekCString s
    newCString $ (filterlines (isInfixOf ii)) ss

freegrep :: CString -> IO ()
freegrep s = free s

foreign export ccall grep :: CString -> CString -> IO CString
foreign export ccall freegrep :: CString -> IO ()

StartEnd.c

#include <Rts.h>

void HsStart()
{
   int argc = 1;
   char* argv[] = {"ghcDll", NULL}; // argv must end with NULL

   // Initialize Haskell runtime
   char** args = argv;
   hs_init(&argc, &args);
}

void HsEnd()
{
   hs_exit();
}

main.cpp中

#include <HsFFI.h>
#include <Grep_stub.h>
#include <iostream>

extern "C" {
    void HsStart();
    void HsEnd();
}

int main(int argc, char* argv[])
{
    HsStart();
    HsPtr str;

    str = grep("test", "This is a test\nwith many lines\nand it failed\nand the test passed");
    if (str)
    {
        std::cout << (char*) str;
        freegrep(str);
    }

    HsEnd();
    return 0;
}

多亏了这些评论,我将实际的错误输出添加到了帖子中。 这使我注意到Visual Studio令人困惑的配置管理界面再次让我难过。 即使我的配置设置为x64它仍在尝试构建Win32版本。 长话短说,它正在工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM