An embarising linking question

I'm trying to write a C++ program in linux, using nano on Gentoo.

I really only just started with this project, and have looked everywhere for the info I need, but I just can't seem to manipulate google to give me the answer I am looking for.

my project is at this point retardedly simple....

1
2
3
4
5
6
7
#include <curses.h>

int main()
{
initscr();
endwin();
}


when I tried the simple gcc compile it spit the message undefined reference to both commands in main()

I knew it was because it was not linking the curses library, so I had a bit of browse trying to find out how to do this...

While browsing I remembered automake and autoconf which I used several months ago, so I installed them - and - after reading several documents on how to use them, I managed to get the message cannot find install-sh or install.sh while executing the ./configure script

This is just wrong - I don't want to install it - it doesn't even do anything, how the hell do I link this file???
Last edited on
In your IDE, try and find a way to link to a library. You want ncurses.lib (might be named 'libncurses.h').

You need to link to the ncurses library. If you compile straight from the command line, add -lncurses, otherwise try and find a way in your IDE to add extra options or libraries.
Well - you kind of hit it on the head - I'm like in a console environment - and as such not using an IDE - infact I'm using nano - which is about the equivelant to Notepad in windows, I think I tried your command line solution earlier which created an a.out file, I'll give it another go in a second and try mucking around with that (maybe this time I might even try executing it).

I'll add - I have no problem coding things in Windows Visual C++ Express, and have done some pretty nifty things with it (atleast in my own league) in the past, but I never have really learnt or even seen much information over the time I've spent programming that really describes the processes going on when I click the BUILD button, ofcourse I see the build output scream up the screen like a depraved demon, it's just a lot of what is going on there has never overly concerned me before....

EDIT: I tried your solution - and examined the created file - it to me appears to be an ELF file of sorts, I had actually somehow wanted to get my snippet above into some kind of low level asm, I don't know a great deal about ELF files, and am only really identifying this file by looking at the first four or five bytes - which strangely enough have the capital letters ELF there, perhaps I am wrong in assuming that this is not assembly - but I would have thought an COM or EXE file would look different

2ND EDIT: I also have good reason (I think) for not installing an IDE - and will be uninstalling the entire tool chain before connecting this computer to the net.
Last edited on
Add "-o myProgram" or "-o myProgram.exe"/".com" if you're on windows/DOS.
thx chrisname, but I'm still getting a file with _ELF as the first 4 bytes :(
If your compiler is designed to create Linux executable you should always get an ELF file
If you want the assembler output

g++ -S foo.cpp

will create foo.s
Oh, I thought he wanted a file he could run.

You can run a.out files btw.
thx, this is what I wanted to know
Topic archived. No new replies allowed.