简体   繁体   English

C ++ libnoise错误到Perlin

[英]c++ libnoise error to Perlin

i installed libnoise on windows with code::blocks 我在Windows上用代码::: blocks安装了libnoise

and at compiling it gives an error: 并在编译时给出错误:

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()'

but the references are in the perlin.h header file 但是引用在perlin.h头文件中

How can i fix this problem? 我该如何解决这个问题?

On Windows, libnoise comes with a *.def file which takes care of exporting symbols. 在Windows上, libnoise带有* .def文件,该文件负责导出符号。 But as I tried to compile the lib in 64 bit this morning, it appeared that this mechanism did not work. 但是,当我今天早上试图以64位编译lib时,似乎这种机制没有用。 I had to "manually" export class symbols : 我不得不“手动”导出类符号:

Steps to export libnoise symbols : 导出libnoise符号的步骤:

. Define a preprocessor variable LIBNOISE_EXPORT when compiling the lib as a shared library, do not add it when compiling a project that uses the lib 定义预处理器变量LIBNOISE_EXPORT编译的lib共享库时,编译使用的lib项目时不添加它

. Add some export macros in a top-level header of the lib (basictypes.h for example): 在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

. Add the LIBNOISE_DLL macro in front of class definition : 在类定义前面添加LIBNOISE_DLL宏:

class LIBNOISE_DLL Perlin: public Module
{
   ...

And that did the trick for me 那对我有用

note : do not use the *.def file in your compilation process if you try this solution 注意:如果尝试此解决方案,请不要在编译过程中使用* .def文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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