I'm trying to link against a C++ file using SWIG but I've hit a stumbling block.
I've got the following files:
foo.cpp
foo.h
fooParser.cpp
fooParser.h
foo.swigcxx
foo_test.go
I can run go build
and go install
just fine, but when I try to run go test
I get a bunch of linker errors similar to
/tmp/go-build806262998/github.com/foo/_test/_obj_test/foo.cpp.o: In function `foo::FooParser::parseX()':./FooParser.cpp:138: undefined reference to `foo::Foo<std::string>::Foo(std::string const&)'
collect2: error: ld returned 1 exit status
/usr/local/go/pkg/tool/linux_amd64/6l: running g++ failed: unsuccessful exit status 0x100
foo.swigcxx
%module foo
%{
#include "foo.h"
#include "fooParser.h"
%}
%include "std_string.i"
%include "foo.h"
%include "fooParser.h"
%template(FooString) Foo<std::string>;
foo.h
#ifndef _H_Foo
#define _H_Foo
#include<string>
namespace foo {
template <class T>
class Foo
{
public:
Foo(const T &initValue = T());
...
};
}
fooParser.h
#ifndef _H_FooParser
#define _H_FooParser
#include "foo.h"
#include <string>
class FooParser
{
public:
...
Foo<std::string> *parse(const std::string &x) throw (Error);
...
private:
Foo<std::string> *parseX() throw(Error);
...
};
Why does it complain that it can't find foo::Foo<std::string>::Foo(std::string const&)
when I have %template(FooString) Foo<std::string>;