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: error while running C application which imports methods from the DLL created using c-shared in go #32101

Closed
Shashi-S opened this issue May 17, 2019 · 4 comments
Labels
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.
Milestone

Comments

@Shashi-S
Copy link

Shashi-S commented May 17, 2019

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

$ go version
1.11

Does this issue reproduce with the latest release?

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\cbairy\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Code\Go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\xyz\AppData\Local\Temp\go-build413893962=/tmp/go-build -gno-record-gcc-switches

What did you do?

Created a simple C console application which imports functions exposed in the DLL and the DLL was created using c-shared. The go DLL depends on other DLL which was created using C++. The dependent DLL are placed in the correct path so console application is able to locate them while loading. "The application was unable to to start correctly(0x0000142)" error is seen while launching console application.

#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) char* testing1(char* input);
__declspec(dllexport) char* testing2(char* input);

#ifdef __cplusplus
}
#endif

check.cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define DllExport __declspec(dllexport)

extern "C" __declspec(dllexport) char* testing1(char* input){
    return input;
}
extern "C" __declspec(dllexport) char* testing2(char* input){
    return input;
}

int main(int argc, char* argv[])
{
    char* result = testing1("testing ");
    std::cout<<"Result : "<< result<<std::endl;
}

Go code for creating DLL which has dependency on above created Check.dll

package main
/*
#cgo LDFLAGS: -lCheck
#include <check.h>
#include <stdlib.h>
#include <string.h>
*/
import "C"
import "fmt"

//export AddTwoNums
func AddTwoNums(numone int, numtwo int) int {
    return numone + numtwo
}

//export Validate
func Validate(args *C.char) *C.char {
    str := C.GoString(args)
    str = str + "-" + str
    return C.CString(str)
}

func importFromClib1() {
    str1 := "Testing1"
    cstr := C.CString(str1)
    result := C.testing1(cstr)
    fmt.Println("Testing1 result : ", C.GoString(result))
}

func importFromClib2() {
    str1 := "Testing2"
    cstr := C.CString(str1)
    result := C.testing2(cstr)
    fmt.Println("Testing2 result : ", C.GoString(result))
}

func main() {
} 

Note: The same sequence works fine on Mac with dylib.

What did you expect to see?

The C console application should run fine without any exception since the application just calls the method from DLL created from go

What did you see instead?

The application was unable to to start correctly(0x0000142)" error is seen while launching C console application.

@FiloSottile FiloSottile changed the title Error while running C application which imports methods from the DLL created using c-shared in go cmd/cgo: error while running C application which imports methods from the DLL created using c-shared in go May 17, 2019
@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 May 17, 2019
@FiloSottile FiloSottile added this to the Go1.13 milestone May 17, 2019
@FiloSottile
Copy link
Contributor

Can you check if this is still an issue with Go 1.12? Thank you!

@Shashi-S
Copy link
Author

I see the same error even with Go 1.12 .
Thank you.

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@ALTree ALTree removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 18, 2021
@qmuntal
Copy link
Contributor

qmuntal commented Apr 1, 2022

I can't reproduce this error, neither with go1.12 nor go1.18, although the steps to reproduce the issue are not clear so I might not be doing exactly the same.

@qmuntal qmuntal added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 28, 2023
@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.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

7 participants