3

我在喝 swig 时遇到了麻烦,对我来说,这似乎是在说我的代码的数据成员之一是未定义的符号。我在网上找到了有关如何修复功能的答案,但这让我感到困惑。

我的错误是:

Traceback (most recent call last):
  File "./test1.py", line 5, in <module>
    from volumes import *
  File "/scratch/rjkern/projects/RJKERN_volrend/scripts/volumes.py", line 26, in <module>
    _volumes = swig_import_helper()
  File "/scratch/rjkern/projects/RJKERN_volrend/scripts/volumes.py", line 22, in swig_import_helper
    _mod = imp.load_module('_volumes', fp, pathname, description)
ImportError: /scratch/rjkern/projects/RJKERN_volrend/scripts/_volumes.so: undefined symbol: _ZN13ConstantColorC1ESt10shared_ptrI5ColorE

这是我的代码:

/*
 *  ColorOperations.h
 */

#ifndef ___COLOROPS___
#define ___COLOROPS___

#include "Color.h"
#include "ProgressMeter.h"
#include "Vector.h"
#include "Volume.h"
#include "VolumeOperations.h"

#include <memory>

using namespace std;

class ConstantColor : public Volume<Color>{
    shared_ptr <Color> color;

public:
    ConstantColor(const shared_ptr<Color>& _color);

    const Color eval(const Vector& P) const;
    Color grad(const Vector& P);
};
#endif

和:

/*
 *  ColorOperations.cpp
 */

#include "ColorOperations.h"

ConstantColor::ConstantColor(const shared_ptr<Color>& _color){
    color = _color;
}

const Color ConstantColor::eval(const Vector& P)const{
    return *color;
}
4

1 回答 1

17

我们可以使用以下命令对符号名称进行分解c++filt

c++filt _ZN13ConstantColorC1ESt10shared_ptrI5ColorE

这给了:

ConstantColor::ConstantColor(std::shared_ptr<Color>)

即你的构造函数,它需要一个shared_ptr. 不过,只会报告第一个未解析的符号。

请注意,这里它不是引用,但您的构造函数看起来像它需要引用。您的 .i 或其他文件中某处可能出现的拼写错误可能会解释为什么某些东西认为存在非参考版本。

另一个可能的解释是您已经将包装器(即编译的volumes_wrap.cxx)构建到共享对象,但没有将编译的ColourOperations.cpp 链接到该对象。

或者,如果您链接它,则可能以错误的顺序链接它,因此链接器将其判断为不需要。如果是这种情况,请确保在链接器命令行上有// last -lcolour_library。(名字有猜测)。colour_library.aColorOperatios.o

于 2012-02-01T20:09:05.950 回答