I'm currently learning how to use c++ and ncurses. Following a tutorial on Youtube I couldn't kepp up because of an error caused when I'm trying to compile my cpp file.
The name of the file is Select.cpp so I'm using the command line gcc -o SELECT Select.cpp -lncurses
to compile it but I keep getting the same error that is:
/tmp/ccirp2Pk.o: En la función `main':
Select.cpp:(.text+0x10e): referencia a `std::allocator<char>::allocator()' sin definir
Select.cpp:(.text+0x127): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' sin definir
Select.cpp:(.text+0x136): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x14d): referencia a `std::allocator<char>::allocator()' sin definir
Select.cpp:(.text+0x166): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' sin definir
Select.cpp:(.text+0x175): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x18c): referencia a `std::allocator<char>::allocator()' sin definir
Select.cpp:(.text+0x1a5): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' sin definir
Select.cpp:(.text+0x1b4): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x217): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const' sin definir
Select.cpp:(.text+0x2cb): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x2df): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x2f3): referencia a `std::allocator<char>::~allocator()' sin definir
Select.cpp:(.text+0x319): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' sin definir
Select.cpp:(.text+0x34c): referencia a `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' sin definir
/tmp/ccirp2Pk.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): referencia a `__gxx_personality_v0' sin definir
collect2: error: ld returned 1 exit status
I have realized that the problem is whenever I'm using string even tho I have included <string>
at the beggining.
The code I'm working is:
#include <ncurses.h>
using namespace std;
#include <string>
int main(int argc, char ** argv){
//Ncurses Starts
initscr();
noecho();
cbreak();
//get screen size
int yMax, xMax;
getmaxyx(stdscr,yMax, xMax);
//create a window for our menu
WINDOW * menuwin = newwin(6, xMax-12, yMax-8, 5);
box(menuwin, 0, 0);
refresh();
wrefresh(menuwin);
//makes it so we can use arrow keys
keypad(menuwin, TRUE);
string choices[3] = {"walk", "jog", "run"};
int choice;
int highlight =0;
while(1){
for(int i=0;i<3;i++){
if(i == highlight){
wattron(menuwin, A_REVERSE);
mvwprintw(menuwin, i+1, 1, choices[i].c_str());
wattroff(menuwin, A_REVERSE);
}
choice = wgetch(menuwin);
switch(choice){
case KEY_UP:
highlight--;
break;
case KEY_DOWN:
highlight++;
break;
default:
break;
}
if(choice=10){
break;
}
}
}
//make sure program waits before exiting
getch();
endwin();
//Ncurses ends
return 0;
}
Thanks for readying and if you can help me I would appreciate it.