LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-10-2003, 09:55 AM   #1
TexasDex
Member
 
Registered: Feb 2003
Location: The Attic. Nowhere near Texas.
Distribution: Gentoo, Kubuntu, formerly LFS, SuSE, and RedHat
Posts: 133

Rep: Reputation: 15
Compiling C++ in Linux


This application which I am trying to port to Linux was written and works fine in the Windows 95 version of DJGPP/RHIDE. I want to compile it to Linux but I can't even get a simple program to compile properly.

I used the command gcc mytest.cpp and got error messages that the function cin was not recognized.

I tried using gcc -x c++ mytest.cpp
and got error messages that the include file was deprecated.

I tried using #include <iostream> instead of iostream.h
I get confusing error messages.

Could somebody point me in the right direction?
 
Old 03-10-2003, 10:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
there were a number of confused people on here asking about all that. it's proably down to the ISO C standards being interpreted differently by different developers... you will need to either export the standard namespace ( using namespace std; ) or clairfy the fill namespace with std::cin wherever just cin is currently used.
 
Old 03-10-2003, 10:15 AM   #3
star geezer
LQ Newbie
 
Registered: Feb 2003
Location: LA
Posts: 17

Rep: Reputation: 0
Try running g++ instead of gcc & see what happens...
 
Old 03-10-2003, 01:01 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Basically it comes down to which compiler lags
behind the standards how far ... I believe it's a
fair bet to assume that the DOS port by Jim is
behind, since he bases on the GNU gcc suite.

If you want best compliance with C++ standards
get & use the STLPort :)

Cheers,
Tink
 
Old 03-10-2003, 01:52 PM   #5
Schizo265
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1, 9.0
Posts: 44

Rep: Reputation: 15
g++
 
Old 03-10-2003, 02:02 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
we have already established that g++ is not the solution, and someone had already stated that solution....
 
Old 03-10-2003, 02:09 PM   #7
Schizo265
Member
 
Registered: Nov 2002
Distribution: Slackware 8.1, 9.0
Posts: 44

Rep: Reputation: 15
oh. Sorry for not reading through.
Why isn't g++ the solution though?
from my personal experience, gcc doesn't work and I get iostream errors, but g++ compiles perfectly.
 
Old 03-10-2003, 03:10 PM   #8
TexasDex
Member
 
Registered: Feb 2003
Location: The Attic. Nowhere near Texas.
Distribution: Gentoo, Kubuntu, formerly LFS, SuSE, and RedHat
Posts: 133

Original Poster
Rep: Reputation: 15
This will sound kinda stupid but how do I run the program after I compile it?

I got it to compile with the gcc and g++ commands, by including the iostream.h header (even though it gave me a warning that it was deprecated) and after it had compiled the file a.out appeared in the directory. Now what do I do? Do I have to link it somehow? Sorry, but I'm used to having a development environment, not this kind of (non)interface.
 
Old 03-10-2003, 03:18 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Nope, just run it :)

./a.out

If you don't like the executables name
use the
-o <your filename>
option...

Cheers,
Tink

Last edited by Tinkster; 03-10-2003 at 03:19 PM.
 
Old 03-10-2003, 11:12 PM   #10
Fingel
Member
 
Registered: Feb 2003
Location: 127.0.0.1
Distribution: Latest Ubuntu
Posts: 161

Rep: Reputation: 30
int main();
using namespace std;

thats the soulution to all your problems, I had the same thing.
 
Old 03-19-2003, 09:22 AM   #11
TexasDex
Member
 
Registered: Feb 2003
Location: The Attic. Nowhere near Texas.
Distribution: Gentoo, Kubuntu, formerly LFS, SuSE, and RedHat
Posts: 133

Original Poster
Rep: Reputation: 15
I don't know what that little bit of code does, but it works. It lets me use the updated header so I don't get a warning message.

And as for running the app, I forgot that Linux doesn't let you type in a command right from the directory it is in. I tried the ./a.out (later I tried the filename ./practice because that's what I renamed it) and it worked fine.

Thanks to all! It works!
 
Old 03-19-2003, 06:04 PM   #12
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Standard C++ now uses a namespace called std.
 
Old 04-03-2003, 03:14 PM   #13
TexasDex
Member
 
Registered: Feb 2003
Location: The Attic. Nowhere near Texas.
Distribution: Gentoo, Kubuntu, formerly LFS, SuSE, and RedHat
Posts: 133

Original Poster
Rep: Reputation: 15
I just realized that the first person who responded answered the question, I just didn't understand what acid_kewpie meant. Fingel clarified how to get it to work even though he might not have understood exactly what the code does (like me). Almost ironic, that those who can often best help newbies are newbies themselves.
 
Old 04-03-2003, 03:19 PM   #14
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
hell yeah. also helps if you can spell, which i can't....
 
Old 04-03-2003, 03:48 PM   #15
nakkaya
LQ Guru
 
Registered: Jan 2003
Location: Turkey&USA
Distribution: Emacs and linux is its device driver(Slackware,redhat)
Posts: 1,398

Rep: Reputation: 45
begin your program like this if you are using new type headers
#include <iostream>
using namespace std;
more info on name spaces
http://faq.cprogramming.com/cgi-bin/...&id=1043284351

and check that if you have any un standart include file for windows.
 
  


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
compiling c++ in linux deapee Programming 14 08-07-2012 11:05 AM
Compiling a program for X-Linux 4.1 steaktc Programming 7 11-01-2005 07:36 AM
compiling linux kernel-2.6.11 kskkumar Linux - Newbie 2 08-22-2005 12:00 PM
compiling .exe in linux bluefusionx Linux - Software 17 12-06-2004 12:19 AM
Compiling C in Linux Neorio Linux - Software 1 09-18-2003 08:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:50 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