运行使用.swigcxx进行测试时无法链接lib

时间:2015-01-13 22:42:37

标签: c++ testing go swig

我正在尝试使用SWIG链接C ++文件,但我遇到了绊脚石。

我有以下文件:

foo.cpp
foo.h
fooParser.cpp
fooParser.h
foo.swigcxx
foo_test.go

我可以正常运行go buildgo install但是当我尝试运行go test时,我收到了一堆类似于

的链接器错误
/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);
  ...
};

为什么我抱怨foo::Foo<std::string>::Foo(std::string const&)

时无法找到%template(FooString) Foo<std::string>;

0 个答案:

没有答案