LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-24-2005, 10:50 PM   #1
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Rep: Reputation: 30
Unhappy C vs C++ .. watta hell's goin'on??


Hello.. just today I made my first program in C (with the help of the people in here) , but what I compile in C, when I try to compile in C++ (with c++ syntax and .cc suffix) returns me a hugh amount of errors ... and I don't know why.. I have searched using google, and I guess I've got all of the requied libraries..really don't know what to think..
Here I paste the error msg, if somebody can figure what's wrong, please let me know, coz I need to compile in c++ . Thanks in advance.

////// Error msg:
gcc: pr: No such file or directory // <- yes it's there!!
In file included from /usr/include/c++/3.3.4/backward/iostream.h:31,
from pr.cpp:2:
/usr/include/c++/3.3.4/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
In file included from /usr/include/bits/posix1_lim.h:126,
from /usr/include/limits.h:144,
from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/include/limits.h:122,
from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/include/syslimits.h:7,
from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/include/limits.h:11,
from /usr/include/c++/3.3.4/climits:49,
from /usr/include/c++/3.3.4/bits/stl_algobase.h:66,
from /usr/include/c++/3.3.4/memory:54,
from /usr/include/c++/3.3.4/string:48,
from /usr/include/c++/3.3.4/bits/locale_classes.h:47,
from /usr/include/c++/3.3.4/bits/ios_base.h:47,
from /usr/include/c++/3.3.4/ios:49,
from /usr/include/c++/3.3.4/ostream:45,
from /usr/include/c++/3.3.4/iostream:45,
from /usr/include/c++/3.3.4/backward/iostream.h:32,
from pr.cpp:2:
/usr/include/bits/local_lim.h:36:26: linux/limits.h: No such file or directory
In file included from /usr/include/errno.h:36,
from /usr/include/c++/3.3.4/cerrno:48,
from /usr/include/c++/3.3.4/bits/locale_facets.tcc:38,
from /usr/include/c++/3.3.4/locale:47,
from /usr/include/c++/3.3.4/bits/ostream.tcc:37,
from /usr/include/c++/3.3.4/ostream:535,
from /usr/include/c++/3.3.4/iostream:45,
from /usr/include/c++/3.3.4/backward/iostream.h:32,
from pr.cpp:2:
/usr/include/bits/errno.h:25:26: linux/errno.h: No such file or directory
 
Old 04-24-2005, 10:57 PM   #2
rununix
LQ Newbie
 
Registered: Aug 2004
Posts: 20

Rep: Reputation: 0
1. it helps to see the code, because we got no clue what your #include's look like
2. You are using deprecated header files in your includes like #include <iostream.h>
What you need to do is use #include <iostream>
3. The above is a general advice. Not all <xxx.h> headers are deprecated though so be careful.
 
Old 04-24-2005, 11:01 PM   #3
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Paste the code you are trying to compile. Lets say you write a program that prints "Hello, World!" to the screen, in C, the syntax is

Code:
#include <stdio.h>
int main (void)
{
      printf ("Hello, World!\n");
      
      return 0;
}
To compile it you would do,
Code:
gcc -o hello hello.c
The same program in c++ would be
Code:
#include <iostream>
using namespace std;
int main (void)
{
      cout << "Hello, World!\n";
      
      return 0;
}
To compile it you would do,
Code:
g++ -o hello hello.cpp
 
Old 04-24-2005, 11:04 PM   #4
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
ok...here's the code.. it's just a hello world one..
#include <stdlib.h>
#include<iostream.h>
int main (void) {

cout<<"hola topu!!"<<endl;
return 0;
}
have in mind I've proved without the .h suffix in the includes, but the result is the same
 
Old 04-24-2005, 11:09 PM   #5
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
hi, reddazz...
plz tell me what's the 2nd line in your cpp example! this:
using namespace std;
it's the very first time I see such code!
 
Old 04-24-2005, 11:37 PM   #6
rununix
LQ Newbie
 
Registered: Aug 2004
Posts: 20

Rep: Reputation: 0
#include <stdlib.h>
#include<iostream>
using namespace std;
int main (void) {

cout<<"hola topu!!"<<endl;
return 0;
}

using namespace std; tells where to look for cout command.
if you don't have that directive you have to do this: std::cout<<....
 
Old 04-24-2005, 11:54 PM   #7
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Quote:
Originally posted by minike
ok...here's the code.. it's just a hello world one..
#include <stdlib.h>
#include<iostream.h>
int main (void) {

cout<<"hola topu!!"<<endl;
return 0;
}
have in mind I've proved without the .h suffix in the includes, but the result is the same
Your code could also be written as below,
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main (void)
{
    cout << "hola topu!!";

    return 0;
}

Last edited by reddazz; 04-24-2005 at 11:56 PM.
 
Old 04-25-2005, 02:59 AM   #8
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
You should remove the <cstdlib> include from the C++-version reddazz posted, it's not used in the program. And you should also consider flushing the output buffer or you might not see the output.
Code:
cout << "hola topu!!" << endl;
takes care of that.
 
Old 04-25-2005, 03:13 AM   #9
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
I put that in so it was the same as his code, but its not necessary for a simple program.
 
Old 04-25-2005, 09:57 AM   #10
minike
Member
 
Registered: Aug 2004
Location: Argentina
Distribution: slackware 12
Posts: 211

Original Poster
Rep: Reputation: 30
ok, pals..
I just fixed the problem: I've had not the kernel-headers library..
that's why I always recommend have in mind my minimal distro..
now it comes all the "deprecated" headers stuff, but they're just warnings -not fatal errors.
tons of thanks to all of you, and to gbonvehi as well.
 
  


Reply



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
Wireless Hell's.... phoenix99 Linux - Wireless Networking 2 05-07-2005 09:23 PM
hell's dell jabberwock486 General 6 12-29-2004 12:01 PM
Where the hell's the floppy disk drive!? xperience Linux - Newbie 3 11-24-2003 09:01 AM
"Where the hell's my...?" no1zhome General 14 04-16-2002 09:28 PM

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

All times are GMT -5. The time now is 07:41 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
Open Source Consulting | Domain Registration