在Python 3.6调用C++扩展时,导入错误“未定义的符号:O.ZNK9FASTNOISE8GETNOISISEFF”

2024-09-28 12:11:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试为Python脚本做一些C++扩展。在故事的C++方面,它似乎编译得很好,它生成了我的^ {< CD1> }共享库,但是当我在python脚本中调用它时,它会引发一个未定义的符号错误。当前代码如下:

#include <iostream>
#include "FastNoise.h"
#include <string>
#include <time.h>

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

#include <boost/python/def.hpp>
#include <boost/python/module.hpp>

using namespace std;
using namespace cv;
namespace bp = boost::python;

int gen(int _size)
{
    FastNoise myNoise;
    myNoise.SetNoiseType(FastNoise::Simplex);
    myNoise.SetSeed((int)(rand() * time(NULL)));

    Size img_size(_size, _size);
    Mat noise_map(img_size, CV_32FC3);

    for (int y = 0; y < _size; y++) {
        for (int x = 0; x < _size; x++) {
            Vec3f &color = noise_map.at<Vec3f>(Point(x, y));
            color.val[0] = (myNoise.GetNoise(x, y) + 1) / 2;
            color.val[1] = (myNoise.GetNoise(x, y) + 1) / 2;
            color.val[2] = (myNoise.GetNoise(x, y) + 1) / 2;
        }
    }

    imshow("test", noise_map);
    waitKey(0);
    return 0;
}

BOOST_PYTHON_MODULE(gen) {
    bp::def("gen", gen);
}

下面是我如何编写的:

^{pr2}$

当我在python中导入它时,会出现以下错误:

>>> import NoiseModule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/matheus/PycharmProjects/TerrainGenerator/NoiseGenerator/NoiseModule.so: undefined symbol: _ZNK9FastNoise8GetNoiseEff
>>> 

在这个问题上的任何帮助都将是非常感谢的。在


Tags: mapsizeincludevalnamespacecolorintgen
1条回答
网友
1楼 · 发布于 2024-09-28 12:11:05

你的共享对象不能访问你使用的每个函数。你可能有一个像快速噪音.cpp它实现了FastNoise对象。但你只使用主.cpp编译动态库(.so)文件。所以确保所有的.cpp文件都包含在PythonC++扩展的构建中。在

另一个选择可能是使FastNoise对象完全在头文件内部实现。在

相关问题 更多 >

    热门问题