Re: [go-nuts] Using C++ code with cgo

2019-04-16 Thread xiang liu
you can see my repo, https://github.com/notedit/media-server-go/tree/master/wrapper use c++ and go, I use swig to generate c++ binding for go av 于2019年4月12日周五 上午1:09写道: > Works like charm. Thanks a lot. > > Here is my code: > > aptwrap.h > > #ifdef __cplusplus > extern "C" { > #endif > > void

Re: [go-nuts] Using C++ code with cgo

2019-04-11 Thread av
Works like charm. Thanks a lot. Here is my code: aptwrap.h #ifdef __cplusplus extern "C" { #endif void print(); #ifdef __cplusplus } #endif aptwrap.cpp #include "aptwrap.h" #include #include #include #ifdef __cplusplus extern "C" { #endif void print() { std::cout << "

Re: [go-nuts] Using C++ code with cgo

2019-04-11 Thread Marcin Romaszewicz
Wrap your C++ code in C. Create a header which is simply: cwrapper.h: void printSomething() Then you can have a cwrapper.cpp instead of your wrapper.hpp: #include extern "C" { void printSomething() { printf("Hello World"); } } Your C++ code will produce a function named printSomething with

[go-nuts] Using C++ code with cgo

2019-04-11 Thread aleksandar . valchev
Hi *, I have following C++ code: wrapper.hpp: #include void printSomething() { printf("Hello World"); } And corresponding main.go: package main // #cgo CXXFLAGS: -I. // #cgo CFLAGS: -I. // #cgo LDFLAGS: // #include "wrapper.hpp" import "C" func main() { C.print() } Unfortunately