Cgo generated sources fail to compile on MVC

Solution 1:

Had the same issue - I ended up commenting out the _Complex types (GoComplex..) as well as the __SIZE_TYPE__ (GoUintPtr) - this way, the .h compiles

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
//typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
//typedef float _Complex GoComplex64;
//typedef double _Complex GoComplex128;

However, I still haven't got it to link using cl:

> cl /EHsc /I ..\libBleveIndexTest main.cpp ..\libBleveIndexTest\libBleveIndexTest.a
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27024.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9024 : unrecognized source file type '..\libBleveIndexTest\libBleveIndexTest.a', object file assumed
main.cpp
Microsoft (R) Incremental Linker Version 14.16.27024.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj
..\libBleveIndexTest\libBleveIndexTest.a
libBleveIndexTest.a(go.o) : warning LNK4078: multiple '.text' sections found with different attributes (60600060)
libBleveIndexTest.a(000005.o) : warning LNK4217: locally defined symbol _errno imported in function x_cgo_sys_thread_create
libBleveIndexTest.a(000007.o) : warning LNK4049: locally defined symbol _errno imported
libBleveIndexTest.a(000005.o) : error LNK2019: unresolved external symbol __imp___iob_func referenced in function _cgo_preinit_init
libBleveIndexTest.a(000006.o) : error LNK2001: unresolved external symbol __imp___iob_func
libBleveIndexTest.a(000007.o) : error LNK2001: unresolved external symbol __imp___iob_func
libBleveIndexTest.a(000005.o) : error LNK2019: unresolved external symbol __imp__beginthread referenced in function x_cgo_sys_thread_create
libBleveIndexTest.a(000007.o) : error LNK2001: unresolved external symbol __imp__beginthread
main.exe : fatal error LNK1120: 2 unresolved externals

The __imp__iob... I can fix by adding:

extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

to the main C source. However, the "__imp__beginthread" I wasn't able to fix.