cmd/go: -buildmode=c-shared without specifying output file fails does not add .dll extension on Windows and .so extension on linux
#38,244 opened on Apr 4, 2020
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
What version of Go are you using (go version)?
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
What did you do?
I tried to build a c-shared library
package main
import "fmt"
import "C"
//export test
func test() {
fmt.Println("Hello World!")
}
func main() {
}
The archive is linked against a C which just calls test() with:
gcc main.c -L<path to dll folder> -l<dll name without extension> -o test.exe
Executing test.exe does not produce any output.
What did you expect to see?
A valid dll file (standard dynamic library format on windows)
What did you see instead?
The call go build -buildmode=c-shareddoes not yield a valid dll (I think; it does not have any extension by default). It produces a [folder name] file without any extension.
I'm not sure what happens, but if you try to link it against a C mainthe main function does not get executed. The linker does not produce any warnings or errors about the file (after renaming [name] to [name].dll).
If you produce the archive with go build -buildmode=c-shared -o <name>.dll everything works as expected, but go build -buildmode=c-shared should be sufficient, but it isn't.