2015-07-02 214 views
1

我試圖使用libnoise library,這是Perlin雜點生成一個C++庫,在Visual Studio 2013教程3個鏈接到名爲noiseutils一個插件工具,它由一個的.cpp和.H,我在這裏舉行:「解析外部符號」錯誤2013

enter image description here

我有項目設置對包括文件夾(其內容如下圖所示)指出,和我的代碼看起來是這樣的。

#include "stdafx.h" 
#include <noise/noise.h> 
#include "noiseutils.h" 


int _tmain(int argc, _TCHAR* argv[]) 
{ 
noise::module::Perlin myModule; 

utils::NoiseMap heightMap; 
utils::NoiseMapBuilderPlane heightMapBuilder; 
heightMapBuilder.SetSourceModule(myModule); 
heightMapBuilder.SetDestNoiseMap(heightMap); 
heightMapBuilder.SetDestSize(256, 256); 
heightMapBuilder.SetBounds(2.0, 6.0, 1.0, 5.0); 
heightMapBuilder.Build(); 

utils::RendererImage renderer; 
utils::Image image; 
renderer.SetSourceNoiseMap(heightMap); 
renderer.SetDestImage(image); 
renderer.Render(); 

utils::WriterBMP writer; 
writer.SetSourceImage(image); 
writer.SetDestFilename("tutorial.bmp"); 
writer.WriteDestFile(); 

return 0; 
} 

所有這些代碼在其網站上提供的第三個教程中給出。 Visual Studio沒有抱怨說它找不到在所有這些代碼中指定的任何類或函數。但是,當我嘗試建立項目...

1>------ Build started: Project: libnoisetest, Configuration: Debug Win32 -- ---- 
1> libnoisetest.cpp 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.h(1217): warning C4244: 'initializing' : conversion from 'const double' to 'float', possible loss of data 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::GradientColor::~GradientColor(void)" ([email protected]@[email protected]@[email protected]) referenced in function "public: __thiscall noise::utils::RendererImage::~RendererImage(void)" ([email protected]@[email protected]@[email protected]) 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::NoiseMap::NoiseMap(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::NoiseMap::~NoiseMap(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::Image::Image(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::Image::~Image(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: void __thiscall noise::utils::WriterBMP::WriteDestFile(void)" ([email protected]@[email protected]@@QAEXXZ) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::NoiseMapBuilderPlane::NoiseMapBuilderPlane(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall noise::utils::NoiseMapBuilderPlane::Build(void)" ([email protected]@[email protected]@@UAEXXZ) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: __thiscall noise::utils::RendererImage::RendererImage(void)" ([email protected]@[email protected]@[email protected]) referenced in function _wmain 
1>libnoisetest.obj : error LNK2019: unresolved external symbol "public: void __thiscall noise::utils::RendererImage::Render(void)" ([email protected]@[email protected]@@QAEXXZ) referenced in function _wmain 
1>B:\Visual Studio\_Projects\libnoisetest\Debug\libnoisetest.exe : fatal error LNK1120: 10 unresolved externals 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

總之,Visual Studio中找不到任何的東西在「noiseutils」,而它的實際建設。我在這裏做錯了什麼?

UPDATE:

由禁衛軍的建議複製noiseutils.cpp到我的源文件夾後,我得到這一套警告,和一個錯誤:

1>------ Build started: Project: libnoisetest, Configuration: Debug Win32 ------ 
1> noiseutils.cpp 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.cpp(24): warning C4627: '#include <fstream>': skipped when looking for precompiled header use 
1>   Add directive to 'stdafx.h' or rebuild precompiled header 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.cpp(26): warning C4627: '#include <noise/interp.h>': skipped when looking for precompiled header use 
1>   Add directive to 'stdafx.h' or rebuild precompiled header 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.cpp(27): warning C4627: '#include <noise/mathconsts.h>': skipped when looking for precompiled header use 
1>   Add directive to 'stdafx.h' or rebuild precompiled header 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.cpp(29): warning C4627: '#include "noiseutils.h"': skipped when looking for precompiled header use 
1>   Add directive to 'stdafx.h' or rebuild precompiled header 
1>b:\visual studio\extra libraries\libnoise\include\noiseutils.cpp(1303): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我擡頭一看這個問題,並發現我可以簡單地使用預編譯頭文件來禁用noiseutils.cpp,因爲它不需要訪問stdafx。這樣,問題就解決了。

出於好奇不過,什麼是stdafx和它在Visual Studio項目中發揮什麼樣的作用?我是否需要禁用爲我的項目添加的任何源代碼禁用預編譯頭文件,以便忽略stdafx?

+1

您需要noiseutils.cpp添加到您的項目。 – Praetorian

+0

事後分析似乎很明顯......我會更新結果。 – ViggyNash

+0

* stdafx.h中*是在爲您的項目預編譯頭(被編譯成* stdafx.cpp *)拉頭的默認名稱。在使用預編譯頭文件時,#include「stdafx.h」需要先於任何其他語句。因此,要麼禁用預編譯頭的項目範圍,或右鍵單擊在Solution Explorer * noiseutils.cpp *,進入屬性,以及地方在C/C++設置,預編譯頭頁上,可以讓你將其關閉的設置爲單個源文件。 – Praetorian

回答

1

右鍵 - >禮儀 - > C++ - >附加包含目錄,並添加頁眉位置

右鍵 - >添加 - >現有項 - >添加文件

如果你想 右鍵點擊 - >添加 - >新的過濾器,你把其中的文件

+0

你必須增加對noiseutils.cpp和YOUT項目文件頭的位置爲好。 – mat