原因
可以在CPP里面引入C++的头文件,但不能在h文件引入
错误
fatal error: cstddef: No such file or directory
测试case,下面的可以,如果把他放到头文件就会报错
// main.go
package main
// #cgo CXXFLAGS: -std=c++11
// #cgo LDFLAGS: -ldl
// #include "test.h"
import "C"
import "fmt"
func main() {
fmt.Println("Size of size_t:", C.get_size())
}
// test.h
#ifdef __cplusplus
extern "C" {
#endif
int get_size();
#ifdef __cplusplus
}
#endif
// test.cpp
#include "test.h"
#include <cstddef>
int get_size() {
return int(sizeof(size_t));
}