簡體   English   中英

swig錯誤:未定義的符號

[英]swig error: Undefined Symbol

我遇到了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;
}

我們可以用c++filt去除符號名稱:

c++filt _ZN13ConstantColorC1ESt10shared_ptrI5ColorE

這給了:

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

即你的構造函數,它采用shared_ptr 但是,只會報告第一個未解決的符號。

請注意,這里它不是引用,但您的構造函數看起來像是引用。 您.i或其他文件中某處可能的拼寫錯誤可能解釋為什么某些東西認為存在非參考版本。

另一個可能的解釋是你已經將你的包裝器(即編譯的volumes_wrap.cxx)構建到共享對象,但沒有將編譯好的ColourOperations.cpp鏈接到該對象。

或者它可能是如果鏈接它,你在錯誤的順序鏈接,並因此不被連接器需要它判斷 如果是這種情況,請確保在鏈接器命令行上最后有-lcolour_library / colour_library.a / ColorOperatios.o (這個名字有猜測)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM