0

So I was writing code for a clear screen function. Everything I had found said to use curse library functions to do this, but I ran into a problem when I had to use initscr() The given error was as follows:

Undefined symbols for architecture x86_64:
  "_initscr", referenced from:
      _main in TheGame...I think.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

As far as I can tell the last two lines are a reference to a different error, so if anyone know what that is that would be great. The current code that is throwing an error is:

#include <iostream>
#include <curses.h>
#include <ctime>

using namespace std;

int main(void){
    //Initializations
    initscr();
    srand(static_cast<int>(time(0)));

    menu();

    return 0;
}

I do know that using namespace std is bad practice, but that is what my book told me to do, menu references a while loop that spreads to other functions by user input that worked perfectly before curses.h and initscr() I have tried putting void and all numbers between 1 and 10 in the parenthesis. Void throws a Parse Issue (Expected '(' for function-style cast or type construction) while the numbers all threw No matching function for call to 'initscr'

using the recommended *initscr(); throws the same error as just plain initscr()

Any and all help is appreciated!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
HadesHerald
  • 131
  • 1
  • 7
  • I doubt that `using namespace std;` is the cause of error here. Looks like your ncurses library was built with a c compiler, and your're missing a `extern "C" { }` wrapping around the `#include `. – πάντα ῥεῖ Oct 28 '14 at 19:29
  • Is there a way to fix this or should I try to find a totally different way of `clrscr`? – HadesHerald Oct 28 '14 at 19:31
  • Did you already check [this Q/A](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). Sounds like you're barking up the wrong tree here. – πάντα ῥεῖ Oct 28 '14 at 19:40
  • So, I read that but it doesn't answer my question, "What do I do to fix it?" I think I understand what is wrong, but I really don't understand what to do about it. – HadesHerald Oct 28 '14 at 22:08

1 Answers1

0

You need to compile and link your program to ncurses: g++ -lncurses <source code>

Your program will probably work now.

fatbu
  • 1
  • 2