1

It is a bit of a newbie question, but I can't seems to make it work.

I know I should use CC=, CXX= and i know the vs compiler name is cl though I'm not sure it is also true for the c++ compiler.

Now assuming the compiler name is cl for both I get the error: go build CC=cl cxx=cl --buildmode=c-shared -o ../lib/core.dll

I get: can't load package: package CC=cl: cannot find package "CC=cl" in any of: ...

If on the other hand I try to compile without the CC / CXX options then it is all working good.

SO to sum it up: 1. what is the c and c++ compiler name for vs? 2. why i get an error when trying to choose which compiler it will use?

Liron Levy
  • 41
  • 1
  • 7
  • MSVC generally doesn't use the CC and CXX variables. Instead, you run your build tool from a CMD shell that has executed vcvarsall.bat from the appropriate VisualStudio install. The usual way to do that is to use the "Visual Studio Command Prompt" shortcuts the VS installer places in the start menu, but you can also just run vcvarsall.bat from any CMD shell. I've never used cgo though, so I don't know for sure that this is the appropriate way to do things with that toolchain. – Miles Budnek May 13 '18 at 09:51

2 Answers2

2

After a few days of playing around it seems that the only working way to create a library that would work with visual studio is to:

  1. create a .dll (using cgo with go 1.10+)
  2. use the bat file or the method mention in HERE to create a stub lib to connect the dll to visual studio.

    • a side note it might be also possible to use loadlibrary func (I did not try that as i tried to avoid this method as it seems to be not a recommended approach).
Liron Levy
  • 41
  • 1
  • 7
2

I tried to use cgo in visual studio with Liron's method with the latest go 1.13. It's working in a little different way. I cannot use the extracted stub lib to connect the dll to visual studio. Instead I have do something that I do not quite understand to make it working:

  1. Create a .dll (with go 1.13 and gcc compiler) with c-shared build mode.
  2. Create a .lib with c-archive build mode.
  3. Use .lib to compile, and use .dll to access all functions. If I directly use .lib, all functions stall when accessing. If I use the extracted stub lib from dll, the program does not even load successfully.