Giter VIP home page Giter VIP logo

simplelib's Introduction

simplelib

This project demonstrates how to create a Go (golang) package from a C++ class using SWIG.

This code was originally for a blog post here: http://zacg.github.io/blog/2013/06/06/calling-c-plus-plus-code-from-go-with-swig/, but the instructions refer to earlier versions of Go (before 1.5) and SWIG (before 3.0).

#####Getting Started

cd $GOPATH
go get github.com/zacg/simplelib
cd $GOPATH/src/github.com/zacg/simplelib
go install -x
go test -v

#####Generating simplelib.go and simplelib_wrap.cxx

These files are needed by simplelib_test.go. You need to do this each time the dependent *.h or *.cpp files change.

swig -go -cgo -c++ -intgosize 64 simplelib.i

To clean up the auto-generated files:

\rm -f simplelib.go simplelib_wrap.cxx 

#####Example Application Code that uses simplelib.go and simplelib_wrap.cxx

You an also look at the unit tests in simplelib_test.go.

package main

import (
	"fmt"
	"github.com/zacg/simplelib"
)

func main() {

	simpleClass := simplelib.NewSimpleClass()
	result := simpleClass.Hello()
	fmt.Println(result)

	strings := simplelib.NewStringVector()
	simpleClass.HelloString(strings)

	var i int64
	for i = 0; i < strings.Size(); i++ {
		fmt.Println(strings.Get(int(i)))
	}

	bytes := simplelib.NewByteVector()
	simpleClass.HelloBytes(bytes)

	for i = 0; i < bytes.Size(); i++ {
		fmt.Printf("%c", bytes.Get(int(i)))
	}
	fmt.Println("")

}

simplelib's People

Contributors

zacg avatar bbigras avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.