C++ libnoise 错误到佩林

c++ libnoise error to Perlin

本文关键字:错误 libnoise C++      更新时间:2023-10-16

我在Windows上安装了带有代码::blocks的libnoise。

在编译时,它会给出一个错误:

undefined reference to `noise::module::Perlin::Perlin()'
undefined reference to `noise::module::Perlin::GetValue(double, double, double) const'
undefined reference to `vtable for noise::module::Perlin'
undefined reference to `noise::module::Module::~Module()'

但引用在perlin.h头文件中

如何解决此问题?

在Windows上,libnoise带有一个*.def文件,用于导出符号。但是当我今天早上尝试以 64 位编译库时,似乎这种机制不起作用。我不得不"手动"导出类符号:

导出 libnoise 符号的步骤:

.定义预处理器变量 LIBNOISE_EXPORT 将 lib 编译为共享库时,编译使用 lib 的项目时不要添加它

.在 lib 的顶级标头中添加一些导出宏(例如 basictypes.h):

#if defined(WIN32)
#   ifdef LIBNOISE_EXPORT
#       define LIBNOISE_DLL __declspec(dllexport)
#   else
#       define LIBNOISE_DLL __declspec(dllimport)
#   endif
#else
#   define LIBNOISE_DLL
#endif

.在类定义前面添加LIBNOISE_DLL宏:

class LIBNOISE_DLL Perlin: public Module
{
   ...

这对我来说是诀窍

注意:如果您尝试此解决方案,请不要在编译过程中使用 *.def 文件