Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: not able to run a golang file that includes C library imports on windows 10 #32490

Closed
jahnavimd opened this issue Jun 8, 2019 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@jahnavimd
Copy link

jahnavimd commented Jun 8, 2019

What version of Go are you using (go version)?

go version go1.10 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

GOARCH=amd64
GOHOSTARCH=amd64
GOHOSTOS=windows
GOOS=windows

What did you do?

package main

// #cgo windows pkg-config: ABC 
// #cgo windows CFLAGS: -DWIN32_LEAN_AND_MEAN
/*
#include <ABC.h>
*/ 
import "C"
import "fmt"
import "unsafe"

func main(){

 inputK  := []byte("abcdefghijklmnopabcdefghijklmnop")
 inputT := []byte("1234567890123456")
 instr := []byte("123-12-1234")

 var cinputKptr *C.uchar = (*C.uchar)(unsafe.Pointer(&inputK[0]))
 var cinputTptr *C.uchar = (*C.uchar)(unsafe.Pointer(&inputT[0]))
 var cinstrptr *C.uchar = (*C.uchar)(unsafe.Pointer(&instr[0]))

var outputtext1, outputtext2 *C.uchar

outputtext1 = C.generateOutput1(cinputKptr, C.int(len(cinputKptr)), cinstrptr, C.int(len(cinstrptr)), cinputTptr, C.int(len(cinputTptr)), 0)

unsafeoutputtext1 := unsafe.Pointer(outputtext1)

outputtext1go := C.GoString((*C.char)(unsafeoutputtext1))
fmt.Println("outputtext1go : ", outputtext1go)

outputtext2 = C.readOutput1(cinputKptr, C.int(len(cinputKptr)), outputtext1, C.int(len(outputtext1go)), cinputTptr, C.int(len(cinputTptr)), 0)
fmt.Println("outputtext2go: ", C.GoString((*C.char)(unsafe.Pointer(outputtext2))))
}

<ABC.h> contains below:

unsigned char* __stdcall generateOutput1(unsigned char* XX, int XX, unsigned char* XX, int XX, unsigned char* XX, int XX, int XX);

unsigned char* __stdcall readOutput1(unsigned char* XX, int XX, unsigned char* XX, int XX, unsigned  char* XX, int XX, int XX);

What did you expect to see?

outputtext1go : Some value
outputtext2go : Some value

What did you see instead?

exit status 3221225781

Note: The same code works fine on Windows 7 with same versions of Go, pkg-config and mingw packages, but doesn't work on Windows 10.

@AlexRouSg
Copy link
Contributor

I'm assuming "ABC" is a .dll, have you completely ruled out issues finding the .dll by making sure it is in the same folder as the executable?

If so then please provide a self contained and minimal reproducer which includes the sources for "ABC" and the pkg-config file, directory layout and exact commands used to build both "ABC" and the go program.

@FiloSottile FiloSottile added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jun 14, 2019
@FiloSottile FiloSottile added this to the Unplanned milestone Jun 14, 2019
@FiloSottile FiloSottile changed the title Not able to run a golang file that includes C library imports on windows 10 cmd/cgo: not able to run a golang file that includes C library imports on windows 10 Jun 14, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Jul 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants