Open

Description
I understand that the go linker cannot currently link msvc object files and also recognize that this issue is likely to be a low priority. However, it would be nice to support this because it would somewhat simplify windows workflow. This issue is mainly to understand how much effort this would be and/or what would be required.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]cgo/ support msvc object files using go linker[/-][+]cmd/link: support msvc object files[/+]bradfitz commentedon Jul 11, 2017
/cc @alexbrainman
alexbrainman commentedon Jul 12, 2017
@xoviat what is the problem that you are having? I need to be able to reproduce it here. So, please, provide all steps I will need to follow to reproduce this.
Thank you
Alex
PS: I won't have computer until end of July. I will have a look at this then.
ghost commentedon Jul 12, 2017
what is the problem that you are having?
I haven't tried it yet, but I would like to specifically call c functions in msvc object files by linking them as .syso with the go linker. Everything that I have read indicates that this is not possible but I will create a procedure to reproduce the specific error that occurs.
alexbrainman commentedon Jul 12, 2017
Have you tried building these into a DLL, and use them from inside of DLL?
Please, do. Thank you.
Alex
ghost commentedon Jul 12, 2017
That was actually my original plan. I am using swig so it is not so convenient to compile the generated c code separately and then rewrite the functions as DLL exports. It's not difficult, but it is annoying when the workflow with gcc is just
go generate; go build
.ghost commentedon Jul 13, 2017
Alright, I have a procedure. Start with these files:
hello.go:
hello.c:
then run these commands (with msvc on path):
Result:
Warning: corrupt .drectve at end of def file
When running the produced file:
alexbrainman commentedon Jul 13, 2017
I do not have cl command installed on my pc. How do I install msvc?
Thank you.
Alex
ghost commentedon Jul 13, 2017
You need the "build tools 2017" here. Microsoft actually now allows anyone to use visual studio for free as long as it's not for commercial development. If it's too much trouble, I can just give you the object file if you want.
ghost commentedon Jul 13, 2017
If only c++ was not a thing, I wouldn't have to worry about this. But it is, so the pain continues...
alexbrainman commentedon Jul 13, 2017
Got it. Thank you.
Yes, please, post hello.obj somewhere.
Thinking about this some more. You are actually using gcc to link object file compiled with msvc compiler. Can you try and do your exercise, but replacing "go build" step with gcc linking hello.obj to a C program? Perhaps it has been done before. I suspect, if we know how to do that, we might be able to do similar with Go.
Alex
ghost commentedon Jul 13, 2017
AFAIK lld https://github.com/llvm-mirror/lld supports msvc object files.
Object file is here: https://github.com/xoviat/msvcgo/blob/master/hello.syso
259 remaining items
hajimehoshi commentedon Jun 14, 2025
I've reported a problem about using MSVC to link a C-archive file generated by Cgo/MinGW (#74189), not creating a C-archive file with MSVC. Is this problem tracked in this issue?
[-]cmd/link: support msvc object files[/-][+]cmd/link: MSVC support (MSVC object + linking with MSVC)[/+]cherrymui commentedon Jun 14, 2025
Currently we don't have any MSVC support. Let's use this issue as a central place for tracking. (I can't edit the original issue content by @ghost, so I just updated the title.)
hajimehoshi commentedon Jun 15, 2025
For #74189, would it make sense to replace fprintf in
runtime/cgo
with some compatible thing, like an original implemetation with WriteConsoleW or OutputDebugStringW for Windows, so that we can avoid this issue?