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/link: support LLVM/Clang for MSVC #54811

Closed
wants to merge 3 commits into from
Closed

Conversation

kkqy
Copy link

@kkqy kkqy commented Sep 1, 2022

I find that cgo can compatible with LLVM/Clang for MSVC well actually.
The only problem I have found is that some arguments for linker of Mingw/GCC can't be used in linker of MSVC, so I write a judgement.
If go detect that the toolchain is LLVM/Clang for MSVC, do not pass those arguments that are not supported by linker of MSVC.

kkqy added 2 commits September 1, 2022 20:25
Detect which toolchain we are using.
if using Clang for MSVC, don't pass those arguments that are not supported by MSVC to the linker.
@gopherbot
Copy link
Contributor

This PR (HEAD: 364c579) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/427515 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@kkqy
Copy link
Author

kkqy commented Sep 1, 2022

Updates #42146
Updates #49080

@kkqy
Copy link
Author

kkqy commented Sep 2, 2022

I find the second problem today that is the program using Clang for MSVC can't be debugged in Go.
I have no idea to fix it because it seems like Golang supports debug info of GCC only.
so this commit only help us to link our golang program to those libraries of built-by-MSVC and closed source.

Mingw/GCC has defferent C++ ABI from MSVC,so we can't use C++ library of MSVC in Mingw/GCC,
but there are so many commercial libraries that are closed source and built by MSVC.
It is regretful if Golang has no easy solution to be compatible with them.

We can build at least now....hm....

@seankhliao
Copy link
Member

please use Gerrit for discussing the change, we don't use GitHub pull requests for this

@gopherbot
Copy link
Contributor

Message from 林志豪:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/427515.
After addressing review feedback, remember to publish your drafts!

@kkqy kkqy closed this Feb 15, 2023
@gatspy
Copy link

gatspy commented Mar 23, 2023

how use msvc complie cgo?

@ianlancetaylor
Copy link
Member

@gatspy Please see https://go.dev/wiki/Questions.

@kkqy
Copy link
Author

kkqy commented Mar 24, 2023

@gatspy you need:

  1. Edit the source like this commit, and remove those flags that are available only in mingw.
  2. Then install the Clang for MSVC (which use MSVC's compiler as its backend), and add the Clang into the PATH.
  3. set environment:
CC="clang"
CXX="clang++"

now, your code in CGO can be compiled by compiler of MSVC.

@vault-thirteen

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants