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

go1.10 build c-shared for to windows dll #23052

Closed
Baozisoftware opened this issue Dec 8, 2017 · 6 comments
Closed

go1.10 build c-shared for to windows dll #23052

Baozisoftware opened this issue Dec 8, 2017 · 6 comments
Labels
FrozenDueToAge OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@Baozisoftware
Copy link

Baozisoftware commented Dec 8, 2017

Glad to see go1.10 support compiled dll, but the following questions (suggestions):

  1. The export function has unnecessary entries;
  2. The output file should be added ". dll" suffix;
  3. Hope that you can specify the value of cgocheck at compile time instead of the runtime specified;
  4. Hope to get rid of symbolic information against static analysis.

Here's the old version of the implementation:
disable cgocheck for golang default

go build to windows dll

Thank golang team for their hard work.

@Baozisoftware Baozisoftware changed the title go1.10 go1.10 build c-shared for to windows dll Dec 8, 2017
@ianlancetaylor
Copy link
Contributor

I'm sorry, I'm not really sure what you mean by any of this. Can you be more specific? Is there any connection between the four things you mention?

CC @nadiasvertex

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 8, 2017
@Baozisoftware
Copy link
Author

Baozisoftware commented Dec 9, 2017

Sorry, my English is poor.

test.go

package main

import "C"

func main(){
}

//export Add
func Add(x,y int)int{
    return x+y
}

//export AddStr
func AddStr(x,y string)string{
    return x+y
}

Use the cmd to build(host:windows/amd64,go1.10b1):

set CGO_ENABLED=1
go build -ldflags="-s -w" -buildmode=c-shared test.go

Yes,i make it,but i have questions:

  1. Output "test" file (no ".dll" suffix,here should be "test.dll");
  2. Use dumpbin view export functions, I found a lot of goruntime functions export, hoping to hide them.
  3. If cgocheck=1(default value),call "Add" funcation is normal,but call "AddStr" is crash,and At the moment can only be set before the call

GODEBUG=cgocheck=0

to solve, I hope we can compile this time instead of running to deal with this issue;

  1. Use -ldflags=-s -w to build Seems to not be able to clear the symbolic information, you can still see a lot of goruntime symbols in IDA, although you can compile it with "strip" to manually clean it and hope it's built-in.

Thanks again.

@ianlancetaylor
Copy link
Contributor

I think these problems will be easier to fix if you file separate issues for separate problems.

Regarding point 3, an exported Go function is not permitted to return a Go string. See https://tip.golang.org/cmd/cgo/#hdr-Passing_pointers .

@Baozisoftware
Copy link
Author

Yes, these issues can be solved manually, but if the merger into the official code may have a better experience? I will modify the source code after the official version go1.10 released, thank you.

@shyandsy
Copy link

@Baozisoftware
I tried this command to build dll library

set CGO_ENABLED=1
go build -ldflags="-s -w" -buildmode=c-shared test.go

when I use this in the VC++ project, VS said "Warning LNK4003 invalid library format; library ignored"

any solution?

@ianlancetaylor
Copy link
Contributor

@shyandsy This issue is closed. I recommend that you use a forum to ask your question. Please see https://golang.org/wiki/Questions .

@golang golang locked and limited conversation to collaborators Nov 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

5 participants