Today when debugging a snake program, the following error occurred:
[email protected] c++]$ g++ snack.cpp-o snack
/TMP/CCCUZ3JM.O: In the function ' PlayGame (int, int) ':
snack.cpp: (. text+0xce): Reference not defined for ' erase '
snack.cpp: (. text+0xed): Reference not defined for ' MVPRINTW '
snack.cpp: (. text+0x140): Reference not defined for ' MVPRINTW '
snack.cpp: (. text+0x166): References not defined for ' move '
snack.cpp: (. text+0x16b): Reference not defined for ' refresh '
/TMP/CCCUZ3JM.O: In the function ' main ':
snack.cpp: (. text+0x2ca): Reference not defined for ' INITSCR '
snack.cpp: (. text+0x2cf): Reference not defined for ' cbreak '
snack.cpp: (. text+0x2d6): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x2e3): Reference not defined for ' keypad '
snack.cpp: (. text+0x2e8): Reference not defined for ' refresh '
snack.cpp: (. text+0x2ef): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x2fb): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x314): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x320): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x35f): References not defined for ' move '
snack.cpp: (. text+0x370): Reference not defined for ' Halfdelay '
snack.cpp: (. text+0x48a): Reference not defined for ' STDSCR '
snack.cpp: (. text+0x492): Reference not defined for ' Wgetch '
snack.cpp: (. text+0x4a9): Reference not defined for ' Endwin '
collect2: Error: LD returns 1
After searching the internet for a long time, I finally found out the problem. Because curses is not the default C function library in Linux, it causes the function definition to not be found at compile time
The correct method is:
[Email protected] c++]$ g++ snack.cpp-o snack-l Curses
[Email protected] c++]$./snack
Curses is not the default C function library in Linux