2016-02-20 69 views
1

我想微軟的Visual Studio 2012下運行下面的C++庫(2010年):NEAT C++編譯器錯誤微軟的Visual Studio 2012

http://nn.cs.utexas.edu/?neat-c

我已經固定了很多編譯器錯誤的,但對於有些問題我找不到解決辦法。 編譯器錯誤是:

1>------ Build started: Project: My_Neuronal_Network, Configuration: Debug Win32 ------ 
1> species.cpp 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\species.cpp(454): warning C4101: 'spin' : unreferenced local variable 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\species.cpp(433): warning C4101: 'pause' : unreferenced local variable 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\species.cpp(453): warning C4101: 'marble' : unreferenced local variable 
1> population.cpp 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\population.cpp(71): warning C4101: 'count' : unreferenced local variable 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\population.cpp(432): warning C4101: 'pause' : unreferenced local variable 
1> genome.cpp 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1777): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1790): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1795): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1845): warning C4018: '<' : signed/unsigned mismatch 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1862): warning C4018: '<' : signed/unsigned mismatch 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1884): warning C4018: '<' : signed/unsigned mismatch 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1888): warning C4018: '<' : signed/unsigned mismatch 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1961): warning C4101: 'p1innov' : unreferenced local variable 
1> experiments.cpp 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(52): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(52): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(52): error C2133: 'evals' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(53): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(53): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(53): error C2133: 'genes' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(54): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(54): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(54): error C2133: 'nodes' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(316): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(316): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(316): error C2133: 'runs' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(512): error C3861: 'lrand48': identifier not found 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(513): error C3861: 'lrand48': identifier not found 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(514): error C3861: 'lrand48': identifier not found 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(515): error C3861: 'lrand48': identifier not found 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(573): warning C4305: 'initializing' : truncation from 'double' to 'const float' 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(575): warning C4305: 'initializing' : truncation from 'double' to 'const float' 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(580): warning C4305: 'initializing' : truncation from 'double' to 'const float' 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(581): warning C4305: 'initializing' : truncation from 'double' to 'const float' 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(623): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(623): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(623): error C2133: 'record' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(625): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(625): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(625): error C2133: 'genesrec' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(627): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(627): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(627): error C2133: 'nodesrec' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(629): error C2057: expected constant expression 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(629): error C2466: cannot allocate an array of constant size 0 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(629): error C2133: 'winnergens' : unknown size 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(692): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\experiments.cpp(706): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 
1> Generating Code... 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(543): error C4703: potentially uninitialized local pointer variable 'bias' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1948): error C4703: potentially uninitialized local pointer variable 'newgene' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1533): error C4703: potentially uninitialized local pointer variable 'newnode' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1777): error C4703: potentially uninitialized local pointer variable 'nodep1' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1777): error C4703: potentially uninitialized local pointer variable 'nodep2' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1808): error C4703: potentially uninitialized local pointer variable 'newgene' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1531): error C4703: potentially uninitialized local pointer variable 'newgene1' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(1532): error C4703: potentially uninitialized local pointer variable 'newgene2' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(2500): error C4703: potentially uninitialized local pointer variable 'chosengene' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(2151): error C4703: potentially uninitialized local pointer variable 'chosengene' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\genome.cpp(2794): error C4703: potentially uninitialized local pointer variable 'chosengene' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\population.cpp(90): error C4703: potentially uninitialized local pointer variable 'new_genome' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\population.cpp(289): error C4703: potentially uninitialized local pointer variable 'new_genome' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\population.cpp(546): error C4703: potentially uninitialized local pointer variable 'best_species' used 
1>c:\users\sebi\desktop\neuroevolution\neat.1.2.1\neat.1.2.1\species.cpp(89): error C4703: potentially uninitialized local pointer variable 'thechamp' used 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

在neat.cpp存在以下定義:

%neat.cpp 
... 
int NEAT::num_runs = 1; 
... 

在接着發生的第一錯誤:

%experiments.cpp 
int evals[NEAT::num_runs]; //Hold records for each run 

所以不知何故該值不不變。如果我使用const int NEAT :: num_runs = 1,我什麼都不會改變;

有人已經使用這個庫,並能夠在Visual Studio下運行這個?

問候 塞比

+1

的代碼依賴於非標準GCC擴展,VLAS不在標準C++法律。重寫它是不實際的,你必須使用GCC。 –

+0

好的,謝謝,我現在使用gcc編譯器的代碼塊。那裏有一些POSIX功能,在Windows下不可用。 strdup()在Windows上有什麼替代方法? – HansPeterLoft

+0

在Windows上,它看起來像函數被稱爲_strdup(),但編譯器仍然說:「_strdup(..)沒有在這個範圍內聲明」#: – HansPeterLoft

回答

1

基本錯誤

error C4703: potentially uninitialized local pointer variable 

只是用NULL草簽變量解決了這個錯誤。但實際上這不是一個錯誤,它是警告,它可能會在項目設置中關閉。發生

錯誤genome.cpp, population.cpp, species.cpp

所以C4703僅在NEAT實施 必不可少的一部分,這意味着它可能會用Visual C++輕易地編譯錯誤。

使用NEAT解決極點平衡任務時會發生其他錯誤。他們可能被視爲使用NEAT的例子。

有人已經使用這個庫,並能夠在Visual Studio下運行這個?

我已經提取NEAT靜態鏈接庫,可以在其他Visual Studio項目中使用。並且在解決方案爲例用法NEAT.lib

第二個項目

You can check my solution here

不是必需的錯誤

error C3861: 'lrand48': identifier not found 

就在VISUALC使用蘭特()++。

error C2133: 'evals' : unknown size 

int evals[NEAT::num_runs]; - 你可以在Visual C使用此++只有NEAT::num_runsconst。編譯器必須知道num_runs的值。

int *evalsPtr = new int[NEAT::num_runs]; - 在其他情況下,使用本

+0

'RAND_MAX'對VC來說很小,所以使用'rand()而不是'lrand48'可能不夠。 – Joey

+0

@Joey我同意你的意見。但是在這個項目的範圍裏,rand()就夠了。在Windows上有沒有更好的'lrand48'替代品,Visual C++? –

+0

好吧,如果較低的'RAND_MAX'不是問題,那麼它應該沒問題,但只要你需要一個大於32767的數字,它就會是,所以我不舒服,簡單地推薦'rand()'作爲替換。 – Joey