LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-29-2004, 10:07 PM   #1
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Rep: Reputation: 30
Compilation Problems


Hi. I have Kernel 2.6.5. Now when I write any program in C++, I get unusual errors during compilation with g++. For example, I just wrote a two statement program.
Code:
#include <iostream>
#include <curses.h>
using namespace std;
int main()
   {
  cout << "Press any key.";
  getch();
  return 0;
  }
Problem is, when I compile, I get 2 errors. One is unresolved reference to stdscr. The other is unresolved reference to wgetch(). I can't compile any program and get some errors or other in the program. Like I tried port programming, but I couldn't get ioperm to be recodnized. I'd included sys/io.h and unistd.h. Can anyone help me?
 
Old 04-29-2004, 10:31 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Did you also upgrade your compiler or libc? Maybe ldd or some other utility used during compiling? binutils?
 
Old 04-30-2004, 01:04 AM   #3
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
Nopes. Nothing. I use the default compiler that comes with Slackware 9.1.
 
Old 04-30-2004, 01:11 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
So you only upgraded your kernel then? I wonder if you removed the kernel source after you compiled it? The weird thing is that wgetch() is a curses function and doesn't have anything to do with the kernel. What command are you using to compile your program?

It should be something like: g++ myprog.cpp -o myprog

Can you copy and paste the whole output from what you're doing with the errors?

Last edited by itsme86; 04-30-2004 at 01:12 AM.
 
Old 05-01-2004, 08:05 AM   #5
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
I get the errors I already mentioned. Unresolved references to wgetch and stdscr. Oh, and I didn't remove the source of the compiler. It's in /usr/src/linux-2.6.4. I don't think I get the errors because of the kernel. I think my C++ compiler has a problem. I compile with g++ myprog.cpp. That's all. Also, I've been programming a lot time in Windows and wanted to shift to Linux. I'm having problems, getting used to the slightly different style. Can anyone point me to some sources that can help me with the equivalent functions in Linux. One more thing, can anybody tell me how I can get my program to recognise a key press within a loop. It just has to know that a key has been pressed and how to retrieve it from the stream. I know in Windows you use kbhit() and getch() to do it. Thanks.
 
Old 05-01-2004, 09:28 AM   #6
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
I believe you need to init curses (w/initscr()) before doing any of this:

Code:
#include <curses.h>
                                                                        
int main(void)
{
        initscr();
        printw("Press any key.");
        getch();
        endwin();
        return 0;
}
and the command to compile is 'g++ -lcurses ./file.cpp -o mybinary'. Also note that <iostream> is unnecessary. Note further that this is just C (but, of course, also valid C++).

Last edited by rkef; 05-02-2004 at 02:40 PM.
 
Old 05-03-2004, 11:05 PM   #7
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
Ok. It works. But why does it work. What does -lcurses do. Also, are there any more parameters I should know about. Not just for curses windows, but generally?
 
Old 05-04-2004, 12:49 AM   #8
rkef
Member
 
Registered: Mar 2004
Location: bursa
Posts: 110

Rep: Reputation: 15
-lcurses links the curses library to your program (quite important ). See the ncurses manpage for tons more information.
 
Old 05-04-2004, 04:11 AM   #9
Grymme
Member
 
Registered: Apr 2004
Location: Sweden
Distribution: Slackware
Posts: 44

Rep: Reputation: 15
> Also, are there any more parameters I should know about. Not just for curses windows, but generally?

Yes!

There are lots and lots of nice flags you can use (for optimizations etc). Don't be afraid to read man-pages since there's where the info you want are.

Here's the stuff about the -l (from gcc manpage) that you were wondering about in this case:

-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files---archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.

Last edited by Grymme; 05-04-2004 at 04:13 AM.
 
Old 05-04-2004, 06:39 PM   #10
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
Oh. Ok. Thanks for the info.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with new kernel compilation (2.4.31) fintanmcevoy Linux - Software 2 11-02-2005 09:27 AM
C++ compilation problems madhatter301 Programming 4 03-16-2005 05:13 PM
Kernel 2.4.22 compilation problems Arcosanti Slackware 3 04-17-2004 12:19 AM
BInutils 2.14 compilation problems Xing Linux - Software 0 09-26-2003 07:04 AM
X compilation problems da Perp Linux From Scratch 2 07-16-2002 02:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration