Hi, I'm using gentoo - its a fairly clean environment - specifically set up for just this one project - ie. almost straight from the Gentoo Handbook (10.1 Gentoo AMD64 No-Multilib gentoo-source kernel).
I was trying to write a simple ncurses program, I have done several projects using Visual C++ for windows, but have ventured into linux for something new.
I have a total of four files, which I will list below, they throw no errors on build, but upon execution, I get a segmentation fault, I'm almost certain it is from the use of ncurses, but I lack experience with linux and ncurses and have exhausted my intellect trying to determine the fault.
The first two files are the Console.h and Console.cpp files...
Console.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#pragma once
class Console
{
public:
Console(void);
~Console(void);
bool Create(void);
private:
void Clear(void);
void Destroy(void);
char* TerminalType;
FILE* InputText;
FILE* OutputText;
SCREEN* ConsoleTerminal;
SCREEN* OriginalTerminal;
WINDOW* ConsoleWindow;
};
|
Console.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include "curses.h"
#include "Console.h"
Console::Console(void)
{
Clear();
}
Console::~Console(void)
{
Destroy();
}
void Console::Clear(void)
{
OutputText=NULL;
InputText=NULL;
TerminalType=NULL;
ConsoleTerminal=NULL;
OriginalTerminal=NULL;
ConsoleWindow=NULL;
return;
}
bool Console::Create(void)
{
OutputText=new FILE;
InputText=new FILE;
TerminalType=(char*)"linux";
ConsoleTerminal=newterm(TerminalType, OutputText, InputText);
OriginalTerminal=set_term(ConsoleTerminal);
ConsoleWindow=initscr();
return true;
}
void Console::Destroy(void)
{
endwin();
set_term(OriginalTerminal);
delscreen(ConsoleTerminal);
Clear();
return;
}
|
This class is invoked by my entry program...
Entry.cpp
1 2 3 4 5 6 7
|
#include "Console.cpp"
int main()
{
Console* output;
output=new Console;
output->Create();
}
|
and built by a rough makefile (please excuse this makefile, I'm real new to this, and kinda had to wing it...)
Makefile
1 2 3 4
|
all:Entry.cpp Console.h Console.cpp
@g++ -g -Wall -l ncurses -o Server Entry.cpp
clean:
@rm -f Server
|
If anyone could explain where I am going wrong, and why this throws a seg fault, I'd be very gratefull for the assistance!