0

I'm trying to use the hunspell library in a Go project on Windows.

I have the compiled Windows DLL (x64) and the corresponding header file (which is written in C), but I can't link it to the Go program.

What I've tried so far:

package main

//#cgo CFLAGS: -Id:/Go/HunSpellTest/build/
//#cgo LDFLAGS: -Ld:/Go/HunSpellTest/build/llibhunspell-1.7-0.dll  -llibhunspell-1.7-0

// #include <stdlib.h>
// #include <hunspell.h>
import "C"

import (
    "unsafe"
)

func main() {
    C.Hunspell_create()
}

But with any combination of the paths and filenames (with extension, without extension, without version number, with relative and absolute path, using slashes or backslashes) I got the same error:

undefined reference to __imp_Hunspell_create

I've tried to add that path to the global PATH variable or put the DLLs into a system wide folder, but nothing worked.

Please note that I can link the DLL with the syscall package and call the Hunspell_create method, but I would like to use the lib like in the hunspellgo package.

Fenistil
  • 3,734
  • 1
  • 27
  • 31

1 Answers1

1

C.Hunspell_create() missing const char* affpath and const char* dpath parameters.

Maybe you also missing some mingw-w64/msys2/cygwin deps packages on Windows. hunspellgo seem not tested on Windows. You needs a linux-like building system (such as mingw-w64/msys2/cygwin) to compile hunspell on Windows. See at https://github.com/hunspell/hunspell#compiling-on-windows . Golang with cgo support on Windows also need some gcc/g++ deps.

raoyc
  • 191
  • 8
  • I know it missing its parameters, but is not the problem. The problem is the compiler can't find the method itself. I have mingw-w64 installed, but I don't want to compile the hunspell package itself on Windows, I would like to use the precompiled DLL. – Fenistil Dec 12 '20 at 10:14
  • You need to `dlltool -dllname hunspell.dll --def hunspell.def --output-lib libhunspell.a`. In gcc/g++ does not using hunspell.dll or hunspell.lib as lib file. – raoyc Dec 12 '20 at 13:05
  • 1
    @Fenistil You can `syscall` a dll file on Windows. But with CGO it needs `lib{name}.a` file. You must generate it first. `undefined reference to __imp_Hunspell_create` means you missing `libhunspell.a` file. see https://cygwin.com/cygwin-ug-net/dll.html . – raoyc Dec 12 '20 at 13:21
  • Thanks, I'll try that and respond – Fenistil Dec 12 '20 at 13:27
  • 1
    @Fenistil maybe you can using this directly: https://github.com/mlt/hunspell/releases/download/tst/hunspell-mingw64.zip – raoyc Dec 12 '20 at 13:29