mjs513
Senior Member+
Trying to work a new project that uses c++ "list" but when I do a compile getting some strange errors. So I went and found a nice simple example:
but this gives me the following error messages:
What I am really trying to get working is a neural network example but can't get past just setting up the "lists" so I can work the other issues. I know its not the whole code but trying to fix the "list" issue first:
but getting the following errors related to "list":
Any help or suggestions would be appreciated.
Thanks
Mike
Code:
// example taken from:
//
//https://en.cppreference.com/w/cpp/container/list
#include <algorithm>
#include <list>
void setup()
{
// Create a list containing integers
std::list<int> l = { 7, 5, 16, 8 };
// Add an integer to the front of the list
l.push_front(25);
// Add an integer to the back of the list
l.push_back(13);
// Insert an integer before 16 by searching
auto it = std::find(l.begin(), l.end(), 16);
if (it != l.end()) {
l.insert(it, 42);
}
// Iterate and print values of the list
for (int n : l) {
Serial.println( n );
}
}
void loop(){}
Arduino: 1.8.7 (Windows 10), TD: 1.44-beta2, Board: "Teensy 3.5, Serial, 120 MHz, Faster, US English"
C:\Users\CYBERP~1\AppData\Local\Temp\arduino_build_993502\sketch\list_example.ino.cpp.o: In function `void std::__cxx11::list<int, std::allocator<int> >::_M_insert<int const&>(std::_List_iterator<int>, int const&)':
c:\local programs\arduino-1.8.7 arm5\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/stl_list.h:1764: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
c:\local programs\arduino-1.8.7 arm5\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/stl_list.h:1764: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
c:\local programs\arduino-1.8.7 arm5\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/stl_list.h:1764: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
C:\Users\CYBERP~1\AppData\Local\Temp\arduino_build_993502\sketch\list_example.ino.cpp.o: In function `std::_List_iterator<int> std::__cxx11::list<int, std::allocator<int> >::emplace<int>(std::_List_const_iterator<int>, int&&)':
c:\local programs\arduino-1.8.7 arm5\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/list.tcc:91: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
collect2.exe: error: ld returned 1 exit status
Error compiling for board Teensy 3.5.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
What I am really trying to get working is a neural network example but can't get past just setting up the "lists" so I can work the other issues. I know its not the whole code but trying to fix the "list" issue first:
Code:
/*Neural Network created by ScottC on 15th Aug 2011
Please visit my blog for a detailed explanation of my Neural Network
http://arduinobasics.blogspot.com/p/arduinoprojects.html
*/
#include <list>
void setup(){
std::list<int> myTrainingInputs();
std::list<int> myTrainingOutputs();
std::list<int>::iterator itTI;
std::list<int>::iterator itTO;
itTI = myTrainingInputs.begin();
itTO = myTrainingOutputs.begin();
float myInputsA[]={0,0};
float myInputsB[]={0,1};
float myInputsC[]={1,0};
float myInputsD[]={1,1};
float myOutputsA[]={1};
float myOutputsB[]={0};
Serial.println("TRAINING DATA");
Serial.println("--------------------------------------------");
myTrainingInputs.insert(itTI, myInputsA);
myTrainingOutputs.insert(itTO,myOutputsA);
itTI++; itTO++;
Serial.println("INPUTS= " + myInputsA[0] + ", " + myInputsA[1] + "; Expected output = " + myOutputsA[0]);
myTrainingInputs.insert(itTI,myInputsB);
myTrainingOutputs.insert(itTO,myOutputsB);
itTI++; itTO++;
Serial.println("INPUTS= " + myInputsB[0] + ", " + myInputsB[1] + "; Expected output = " + myOutputsB[0]);
myTrainingInputs.insert(itTI,myInputsC);
myTrainingOutputs.insert(itTO,myOutputsB);
itTI++; itTO++;
Serial.println("INPUTS= " + myInputsC[0] + ", " + myInputsC[1] + "; Expected output = " + myOutputsB[0]);
myTrainingInputs.insert(itTI,myInputsD);
myTrainingOutputs.insert(itTO,myOutputsA);
Serial.println("INPUTS= " + myInputsD[0] + ", " + myInputsD[1] + "; Expected output = " + myOutputsA[0]);
Serial.println("--------------------------------------------");
NeuralNetwork NN = new NeuralNetwork();
NN.addLayer(2,2);
NN.addLayer(2,1);
Serial.println("Before Training");
float myInputDataA1[]={0,0};
NN.processInputsToOutputs(myInputDataA1);
float myOutputDataA1[]={};
myOutputDataA1=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 0,0; OUTPUT=" + myOutputDataA1[0]);
float myInputDataB1[]={0,1};
NN.processInputsToOutputs(myInputDataB1);
float myOutputDataB1[]={};
myOutputDataB1=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 0,1; OUTPUT=" + myOutputDataB1[0]);
float myInputDataC1[]={1,0};
NN.processInputsToOutputs(myInputDataC1);
float myOutputDataC1[]={};
myOutputDataC1=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 1,0; OUTPUT=" + myOutputDataC1[0]);
float myInputDataD1[]={1,1};
NN.processInputsToOutputs(myInputDataD1);
float myOutputDataD1[]={};
myOutputDataD1=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 1,1; OUTPUT=" + myOutputDataD1[0]);
Serial.println("");
Serial.println("--------------------------------------------");
Serial.println("Begin Training");
NN.autoTrainNetwork(myTrainingInputs,myTrainingOutputs,0.0001,500000);
Serial.println("");
Serial.println("End Training");
Serial.println("");
Serial.println("--------------------------------------------");
Serial.println("Test the neural network");
float myInputDataA2[]={0,0};
NN.processInputsToOutputs(myInputDataA2);
float myOutputDataA2[]={};
myOutputDataA2=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 0,0; OUTPUT=" + myOutputDataA2[0]);
float myInputDataB2[]={0,1};
NN.processInputsToOutputs(myInputDataB2);
float myOutputDataB2[]={};
myOutputDataB2=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 0,1; OUTPUT=" + myOutputDataB2[0]);
float myInputDataC2[]={1,0};
NN.processInputsToOutputs(myInputDataC2);
float myOutputDataC2[]={};
myOutputDataC2=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 1,0; OUTPUT=" + myOutputDataC2[0]);
float myInputDataD2[]={1,1};
NN.processInputsToOutputs(myInputDataD2);
float myOutputDataD2[]={};
myOutputDataD2=NN.getOutputs();
Serial.println("Feed Forward: INPUT = 1,1; OUTPUT=" + myOutputDataD2[0]);
}
void loop(){}
NN_AB: In function 'void setup()':
NN_AB:15: error: request for member 'begin' in 'myTrainingInputs', which is of non-class type 'std::__cxx11::list<int>()'
itTI = myTrainingInputs.begin();
^
NN_AB:16: error: request for member 'begin' in 'myTrainingOutputs', which is of non-class type 'std::__cxx11::list<int>()'
itTO = myTrainingOutputs.begin();
^
NN_AB:29: error: request for member 'insert' in 'myTrainingInputs', which is of non-class type 'std::__cxx11::list<int>()'
myTrainingInputs.insert(itTI, myInputsA);
^
NN_AB:30: error: request for member 'insert' in 'myTrainingOutputs', which is of non-class type 'std::__cxx11::list<int>()'
myTrainingOutputs.insert(itTO,myOutputsA);
Any help or suggestions would be appreciated.
Thanks
Mike