简体   繁体   中英

swig error: Undefined Symbol

I'm having trouble with swig and to me it looks like it is saying that one of the data members of my code is an undefined symbol. I have found answers online on how to fix functions but this is puzzling me.

My error is:

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

And this is my code:

/*
 *  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

And:

/*
 *  ColorOperations.cpp
 */

#include "ColorOperations.h"

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

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

We can de-mangle the symbol name with c++filt :

c++filt _ZN13ConstantColorC1ESt10shared_ptrI5ColorE

Which gave:

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

ie your constructor which takes a shared_ptr . Only the first unresolved symbol will be reported though.

Notice that here it's not a reference, but your constructor looks like it takes a reference. Possible typo somewhere in your .i or other files might explain why something thinks there's a non-reference version.

The other likely explanation for that would be that you've built your wrapper, (ie compiled volumes_wrap.cxx) to a shared object, but not linked your compiled ColourOperations.cpp to that object.

Alternatively it's possible that if you have linked it you linked it in the wrong order and thus it was judged as not needed by the linker . If that's the case make sure you have the -lcolour_library / colour_library.a / ColorOperatios.o last on the linker command line. (The name there was speculation).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM