smimesign icon indicating copy to clipboard operation
smimesign copied to clipboard

Not able to compile on Windows

Open sudhabindu-apm opened this issue 1 year ago • 2 comments

For the following block of code:

store, err := certstore.Open()
	if err != nil {
		return nil, err
	}
	defer store.Close()

I get the following error:

➜  certstore-test env GOOS=windows GOARCH=amd64  go build
# github.com/github/smimesign/certstore
../../../go/pkg/mod/github.com/github/[email protected]/certstore/certstore.go:17:9: undefined: openStore

Go version: go1.22.1 Platforms: macOS(arm64), windows (amd64)

The code compiles fine for macOS, it fails for Windows when trying from macOS or Windows.

sudhabindu-apm avatar Apr 08 '24 13:04 sudhabindu-apm

I have the same problem, Did you solve it?

rthacker87 avatar May 08 '24 02:05 rthacker87

@rthacker87 No, I haven't solved it ☹️

sudhabindu-apm avatar Jun 14 '24 10:06 sudhabindu-apm

I was puzzled by this as well. I discovered that the problem is that anything that includes C code directly like this package does needs a C compiler configured ready to go. This is often the case on a Mac, but unfortunately is not the case on windows.

I am building on GO 1.20.

I installed mingw with choco: choco install mingw and made sure that the C:\ProgramData\mingw64\mingw64\bin path was added and then it worked.

I did run into a problem with certstore\certstore_windows.go:641:29: cannot convert cmsg (variable of type *_Ctype_char) to type _Ctype_HANDLE so I just commented it out...

//defer C.LocalFree(C.HLOCAL(cmsg))

UPDATE: The proper fix is in https://github.com/github/smimesign/pull/114/commits/84f3ae395fee57ef8dd82802cef0d27f25a1b9ef defer C.LocalFree(C.HLOCAL(unsafe.Pointer(cmsg)))

craigdfrench avatar Jul 20 '24 20:07 craigdfrench