undefined reference to `std::__detail::_List_node_base::_M_hook() and unhook()

Status
Not open for further replies.
Out of curiosity i was trying to run my own version of the array vs linked list benchmark to see how it fairs on the teensy, but i get the following compile error in Arduino 1.05

Code:
vecotrVsLinkedList.cpp.o: In function `emplace<int>':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/bits/list.tcc:92: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
vecotrVsLinkedList.cpp.o: In function `std::list<int, std::allocator<int> >::_M_erase(std::_List_iterator<int>)':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/bits/stl_list.h:1542: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
collect2: error: ld returned 1 exit status

here's my code
Code:
#include <list>
#include <vector>

int n = 10;

void setup()  {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) { }
}

void loop() {
  delay(200);
  
  myTest(n);

  n++;
}

void myTest(int n) {
  Serial.print("\nlinked list size:");
  Serial.print(n);
  unsigned long execTime = micros();

  testList(n);

  execTime = execTime - micros();
  Serial.print(" test took: ");
  Serial.print(execTime);
  Serial.println(" micros");


  Serial.print("\nvector list size:");
  Serial.print(n);
  execTime = micros();
  
  testVector(n);

  execTime = execTime - micros();
  Serial.print(" test took: ");
  Serial.print(execTime);
  Serial.println(" micros");

}

void testList(int n) {

  //create random number generator with pi seed
  srand(314159265359);

  //create datastructure
  std::list<int> l;

  //insert n things
  int m = n;
  int i = 0;
  while (n) {
    //insert in random position
    int insertIndex = rand() % i++;
    auto it = l.begin();
    for(int j=0; i<insertIndex; j++) {
      ++it;
    }
    l.insert(it, (rand() % 1000000000));
    --n;
  }

  //dequeue m things
  while (m) {
    int eraseIndex = (rand() % m);
    auto it = l.begin();
    for(int j=0; i<eraseIndex; j++) {
      ++it;
    }
    l.erase(it);
    --m;
  }

}

void testVector(int n) {

  //create random number generator with pi seed
  srand(314159265359);

  //create datastructure
  std::vector<int> v;

  //insert n things
  int m = n;
  int i = 0;
  while (n) {
    //insert in random position
    int insertIndex = rand() % i++;
    auto it = v.begin();
    for(int j=0; j<insertIndex; j++) {
      ++it;
    }
    v.insert(it, (rand() % 1000000000));
    --n;
  }

  //dequeue m things
  while (m) {
    int eraseIndex = (rand() % m);
    auto it = v.begin();
    for(int j=0; i<eraseIndex; j++) {
      ++it;
    }
    v.erase(it);
    --m;
  }

}
 
another version of the code, looks like inserting into an empty list was a no no, this version works on cpp.sh and on an mbed, but teensy doesn't seem to like the Container type, and still getting a weird error


Code:
vecotrVsLinkedList.cpp.o: In function `std::vector<int, std::allocator<int> >::_M_check_len(unsigned int, char const*) const':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/bits/stl_vector.h:1306: undefined reference to `std::__throw_length_error(char const*)'
vecotrVsLinkedList.cpp.o: In function `__gnu_cxx::new_allocator<int>::allocate(unsigned int, void const*)':
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/ext/new_allocator.h:92: undefined reference to `std::__throw_bad_alloc()'
/Applications/Arduino105.app/Contents/Resources/Java/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/include/c++/4.7.2/ext/new_allocator.h:92: undefined reference to `std::__throw_bad_alloc()'
collect2: error: ld returned 1 exit status

Code:
#include <list>
#include <vector>

int n = 2;

void setup()  {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) { }

  //create random number generator with pi seed
  srand(314159265359);
}

// template <typename Container>
// void test(Container &c, int n) {
void test(std::vector<int> &c, int n) {

  //insert n things
  int m = n;
  int i = 1;
  int insertFirst = (rand() % 1000000000);
  Serial.print("insertFirst:");
  Serial.println(insertFirst);
  c.push_back(insertFirst);
  while (n) {
    //insert in random position
    int insertIndex = (rand() % i++);
    Serial.print("n:");
    Serial.println(n);
    Serial.print("insertIndex:");
    Serial.println(insertIndex);
    auto it = c.begin();  
    for(int j=0; j<insertIndex; j++) {
      Serial.print("j:");
      Serial.println(j);
      ++it;
    }
    Serial.println("insert");
    c.insert(it, (rand() % 1000000000));
    --n;
  }
// Serial.println("\ncheck"); // -------------------------------------------

  //dequeue m things
  while (m) {
    int eraseIndex = (rand() % m);
    Serial.print("m:");
    Serial.println(m);
    Serial.print("eraseIndex:");
    Serial.println(eraseIndex);
    auto it = c.begin();
    for(int j=0; j<eraseIndex; j++) {
      Serial.print("j:");
      Serial.println(j);
      ++it;
    }
    c.erase(it);
    --m;
  }

} 

void loop() {
  delay(200);
  
  // Serial.print("\nlinked list size:");
  // Serial.print(n);
  // unsigned long execTime = micros();

  // std::list<int> l;
  // test(l, n);

  // execTime = execTime - micros();
  // Serial.print(" test took: ");
  // Serial.print(execTime);
  // Serial.println(" micros");


  Serial.print("\nvector list size:");
  Serial.println(n);
  unsigned long execTime = micros();
  
  std::vector<int> v;
  test(v, n);

  execTime = execTime - micros();
  Serial.print(" test took: ");
  Serial.print(execTime);
  Serial.println(" micros");

  n*2;
}
 
Status
Not open for further replies.
Back
Top