Error compiling a C file generated from Golang: error C2146: syntax error: missing ';' before identifier 'GoComplex64'

David Choi 20 Reputation points

I am trying to compile into C++ a shared dll that was generated using Golang as a C binary. And I'm running the compilation using Gyp on Github Actions. This compilation works on both a Mac M1 and Mac x64, but is failing due to these errors.

Does anyone know how to do this? Here's the C header and the logs.

/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package archwayhq/keyring-go/src/go */

#line 1 "cgo-builtin-export-prolog"

#include <stddef.h>


typedef struct { const char *p; ptrdiff_t n; } _GoString_;


/* Start of preamble from import "C" comments.  */

#line 3 "main.go"
#include <stdlib.h>
#include <idl_export.h>

#line 1 "cgo-generated-wrapper"

/* End of preamble from import "C" comments.  */

/* Start of boilerplate cgo prologue.  */
#line 1 "cgo-gcc-export-header-prolog"


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_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

  static assertion to make sure the file is being used on architecture
  at least with matching size of GoInt.
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

typedef _GoString_ GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;


/* End of boilerplate cgo prologue.  */

#ifdef __cplusplus
extern "C" {

extern void SetOsStore(char* serviceName, char* keyName, char* data);
extern char* GetOsStore(char* serviceName, char* keyName);

// note: ~/ is root of user dir
extern char* SetFileStore(char* fileSaveDir, char* fileName, char* data);
extern char* GetFileStore(char* fileSaveDir, char* fileName);

#ifdef __cplusplus

Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.

  nothing.vcxproj -> D:\a\keyring-go\keyring-go\build\Release\\nothing.lib
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.34.31933\include\ccomplex(22,52): warning C4996: '_Header_ccomplex': warning STL4004: <ccomplex>, <cstdalign>, <cstdbool>, and <ctgmath> are deprecated in C++17. You can define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to suppress this warning. [D:\a\keyring-go\keyring-go\build\keyring-go.vcxproj]
D:\a\keyring-go\keyring-go\build\cgo-gcc-export-header-prolog(20,30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\keyring-go\keyring-go\build\keyring-go.vcxproj]
D:\a\keyring-go\keyring-go\build\cgo-gcc-export-header-prolog(20,19): error C2146: syntax error: missing ';' before identifier 'GoComplex64' [D:\a\keyring-go\keyring-go\build\keyring-go.vcxproj]
D:\a\keyring-go\keyring-go\build\cgo-gcc-export-header-prolog(21,31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [D:\a\keyring-go\keyring-go\build\keyring-go.vcxproj]
D:\a\keyring-go\keyring-go\build\cgo-gcc-export-header-prolog(21,19): error C2146: syntax error: missing ';' before identifier 'GoComplex128' [D:\a\keyring-go\keyring-go\build\keyring-go.vcxproj]
gyp ERR! build error 
gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\a\keyring-go\keyring-go\node_modules\node-gyp\lib\build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Windows_NT 10.0.20348
gyp ERR! command "C:\\hostedtoolcache\\windows\\node\\18.14.2\\x64\\node.exe" "D:\\a\\keyring-go\\keyring-go\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd D:\a\keyring-go\keyring-go
gyp ERR! node -v v18.14.2
gyp ERR! node-gyp -v v9.3.1
gyp ERR! not ok 
Error: Process completed with exit code 1.
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,743 questions
{count} votes

Accepted answer
  1. Viorel 88,316 Reputation points

    Try adjusting the #ifdef _MSC_VER ... #endif portion:

    #ifdef _MSC_VER
    #  if _MSVC_LANG <= 201402L
    #    include <complex.h>
         typedef _Fcomplex GoComplex64;
         typedef _Dcomplex GoComplex128;
    #  else
    #    include <complex>
         typedef std::complex<float> GoComplex64;
         typedef std::complex<double> GoComplex128;
    #  endif
      typedef float _Complex GoComplex64;
      typedef double _Complex GoComplex128;

    If this modification cannot be done, then try using a compiler option related to ISO C++14 Standard (/std:c++14).

    If you are using Visual Studio 2022, see Project Properties, General, C++ Language Standard.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful