Skip to content

Instantly share code, notes, and snippets.

@justinfx
Last active December 29, 2015 18:49
Show Gist options
  • Save justinfx/7712860 to your computer and use it in GitHub Desktop.
Save justinfx/7712860 to your computer and use it in GitHub Desktop.
Broken cgo / C++ test for Go, trying to wrap OpenColorIO
$ go build -x -v .
# swigtest/ocio
ocio/ocio.cpp:24:16: error: no viable conversion from 'OCIO::ConstConfigRcPtr' (aka 'shared_ptr<const OpenColorIO::v1::Config>') to 'Config *' (aka 'void *')
/usr/include/c++/4.2.1/tr1/boost_shared_ptr.h:678:7: note: candidate function
#include <OpenColorIO/OpenColorIO.h>
#include "ocio.h"
extern "C" {
namespace OCIO = OCIO_NAMESPACE;
// Global
void ClearAllCaches() {
OCIO::ClearAllCaches();
}
const char* GetVersion() {
return OCIO::GetVersion();
}
int GetVersionHex() {
return OCIO::GetVersionHex();
}
// Config
Config* GetCurrentConfig() {
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
return config;
}
// const char* Config_getDescription(Config *p) {
// return reinterpret_cast<OCIO::ConstConfigRcPtr>(*p)->getDescription();
// }
}
package ocio
/*
#cgo LDFLAGS: -lstdc++
#cgo pkg-config: OpenColorIO
#include "ocio.h"
*/
import "C"
func ClearAllCaches() {
C.ClearAllCaches()
}
func GetVersion() string {
return C.GoString(C.GetVersion())
}
func GetVersionHex() C.int {
return C.GetVersionHex()
}
// type Config struct {
// ptr C.ConstConfigRcPtr
// }
// func GetCurrentConfig() Config {
// c := Config{C.GetCurrentConfig()}
// return c
// }
#ifndef _SWIGTEST_OCIO_H_
#define _SWIGTEST_OCIO_H_
#ifdef __cplusplus
extern "C" {
#endif
// Global
void ClearAllCaches();
const char* GetVersion();
int GetVersionHex();
// Config
typedef void Config;
Config* GetCurrentConfig();
// const char* Config_getDescription(Config p);
#ifdef __cplusplus
}
#endif
#endif
package ocio
import "testing"
import "fmt"
func TestClearAllCaches(t *testing.T) {
ClearAllCaches()
}
func TestGetVersion(t *testing.T) {
fmt.Println(GetVersion())
}
func TestGetVersionHex(t *testing.T) {
fmt.Println(GetVersionHex())
}
// func TestGetCurrentConfig(t *testing.T) {
// c := GetCurrentConfig()
// fmt.Println(c)
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment