C++ Bindings, CGO

I am trying to compile simple c++ code with golang but there are a few errors:

// namespace test
// {
//     int val = 500;
// }
import "C"

Output: error: unknown type name ‘namespace’
This is most likely because the the compiler is for C and not C++; how can I change this?

// #include <algorithm>
import "C"

Output: fatal error: algorithm: No such file or directory
The include file exists and is found by g++; but the go compiler does not find the file. What do I need to change here? I do not want to include every folder manually.
It’s a C++ header file at /usr/include/c++/8/algorithm; are these headers not included because it’s C and not C++?

I have seen the howto-go-with-cpp but this workaround is not good for the build stack and the deps that I use because it requires to modify the included header files.

Go verions: go1.11.6 linux/arm on a RPi.


The other example uses the same technique as the link that I postet: They create an extra C header and compile the C++ files as libraries which i tried to avoid.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.