I am trying to wrap C++ code (LabStreamingLayer) in Go.
Update: @dragonx explained how to use go build without swig. But I am still running into a linker issue. The build depends on LSL/liblsl/bin/liblsl.dylib. How do I tell go build to use that file? I tried go build -ldflags "-L ../liblsl/bin -l lsl" app.go with no success.
The Go documentation says that go build will invoke Swig with the c++ option for files with the .swigcxx extension, but go build complains that there are no buildable Go source files in the directory.
- Platform: Darwin
- Go version: 1.8
- Swig version: 3.0.12
- clang version: 8.0.0
Here are the steps I took to arrive at that error:
- Clone the labstreaminglayer repo.
- Rename the file
liblsl_cpp.itoliblsl.swigcxx(I thought this would tellgo buildthat the file should be used with swig). cdintoLSL/liblsl-Genericand rungo build. Go complains that there are no buildable Go source files in this directory.
After that failed, I tried using Swig. I ran swig -c++ -go -cgo -intgosize 64 liblsl_cpp.i, which created a .go file. I then ran go build in that directory, but it raised the error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
I am not familiar with C++, so I am not sure how to resolve the linker issue. I do know that this C++ code requires the file LSL/liblsl/bin/liblsl64.dylib. I assume that is the file that must be linked?
How can I wrap this C++ code in Go?
Here is the file structure:
LSL
├── liblsl
│ ├── bin
│ ├── distros
│ ├── examples
│ ├── external
│ ├── include
│ ├── project
│ ├── src
│ └── testing
└── liblsl-Generic
├── AUTOGENERATE\ HOWTO.txt
├── examples
├── liblsl.swigcxx
├── liblsl_c.i
├── liblsl_cpp.i
├── liblsl_wrap.cxx # created by Swig
└── liblsl.go # created by Swig