Skip to content

Using cgo built DLL on Visual Studio Project #49080

Closed
@ghost

Description

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

go version go1.15.6

Does this issue reproduce with the latest release?

I have not checked on go1.17 yet.

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

windows/amd64

What did you do?

I want to use a golang module as c-shared library and then call it from a MFC application.

  1. I built the go module as c-shared library(example.dll) and example.h file successfully.
  2. I created simple C program, included example.h file and called my library function, I built the program with gcc command, everything worked as expected.
  3. On MFC project, included example.h file and called my library function, then used VS2019 Community to build. Error came out.
error E0020: identifier "__SIZE_TYPE__" is undefined
error E0065: expected ';'
error C2143: syntax error : missing '}' before 'enum [tag]'

I checked on Internet and found out that the problem is about compiler.
On VS2019, they use msvc as compiler for C program so when I include a cgo built library (which is using gcc by default) on VS2019 project, there are some conflicts between them.

I tried to find a way to build my golang module to c-shared library with msvc compiler and found this.
https://go-review.googlesource.com/c/go/+/133946

Unfortunately, this [cmd/compile: add support for MSVC toolchain to go build] change is still in review.

What did you expect to see?

So if there is an official guide about using cgo built library on VS2019, I would be happy.

What did you see instead?

Included in [What di you do?] section.

Activity

ianlancetaylor

ianlancetaylor commented on Oct 20, 2021

@ianlancetaylor
Contributor

I'm sorry, using any compiler other than GCC or clang is currently unsupported.

Closing as a dup of #20982.

locked and limited conversation to collaborators on Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ianlancetaylor@gopherbot

        Issue actions

          Using cgo built DLL on Visual Studio Project · Issue #49080 · golang/go