LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-11-2010, 01:22 PM   #1
jmalbornoz
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Rep: Reputation: 0
Trying to compile C++ in Suse 11.1


Hi all,

I am trying to learn C++ by myself. I just wrote my first code lines but I am unable to compile them, I keep getting "fig15_1.cpp:2: iostream: No such file or directory". I have tried gcc and g++ (both installed in my system) but to no avail. The following is my code

Code:
// Entrada/salida en C++
#include <iostream>
using namespace std;

main()
{

   cout << "Ingresa tu edad: ";
   int myAge;
   cin >> myAge;

   cout << "Ingresa la edad de tu amigo: ";
   int friendsAge;
   cin >> friendsAge;

   if(myAge > friendsAge)
      cout << "Eres el mayor!";
   else 
      if(myAge < friendsAge)
         cout << "Eres mas joven!"
      else
         cout << "Tienen la misma edad!"   

   return 0;
}
I also tried both <iostream> and <iostream.h>: same story!

This is what is installed in my system

PHP Code:

Name          Summary                                       Type
--+---------------+-----------------------------------------------+--------
gcc           The system GNU C Compiler                     package
gcc-c++       | The system GNU C++ Compiler                   package
gcc-gij       The system GNU Java bytecode interpreter      package
gcc-info      The system GNU Compiler documentation         package
gcc-java      The system GNU Java Compiler                  package
gcc33         The GNU C Compiler Version 3.3(evaluation)    | package
gcc33-fortran The GNU Fortran 77 Compiler and Support Files package
gcc43         The GNU C Compiler and Support Files          package
gcc43-c++     | The GNU C++ Compiler                          package
gcc43-fortran The GNU Fortran Compiler and Support Files    package
gcc43-gij     Java Bytecode Interpreter for gcc             package
gcc43-info    Documentation for the GNU compiler collection package
gcc43-java    The GNU Java Compiler                         package
gcc43-objc    GNU Objective C Compiler                      package
libgcc43      C compiler runtime library                    package 
PHP Code:
Name              Summary                                               Type
--+-------------------+-------------------------------------------------------+--------
libstdc++-devel   The system GNU C++ development files                  package
libstdc++33       The standard C++ shared library                       package
libstdc++41-doc   Documentation for the GNU C++ standard library        package
libstdc++43       The standard C++ shared library                       package
libstdc++43-devel | Include Files and Libraries mandatory for Development package 
Any help/suggestions/hints are greatly appreciated!
 
Old 01-11-2010, 02:13 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Exactly what command are you using to compile your code?
 
Old 01-11-2010, 02:27 PM   #3
jmalbornoz
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0
I am using "gcc code.cpp" and also tried "g++ code.cpp"...
 
Old 01-11-2010, 03:54 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
You're missing semicolons on line 20 and 22. After adding those, compiling with g++ works for me. Sadly I don't know what you need to install to get the headers since I don't use SuSE.
 
Old 01-11-2010, 05:39 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by AlucardZero View Post
I don't know what you need to install to get the headers since I don't use SuSE.
I don't use SuSE either. But iostream is in libstdc++-devel in lots of other distributions. Since the OP listed that package as installed, it is safe to conclude he has iostream.

So why doesn't g++ find iostream.

I don't remember enough about the diagnostic options to determine why g++ isn't finding something. But the simplest is

g++ -v code.cpp

then look at the specs file it mentions.

You might also check whether iostream is in the usual place using

ls /usr/include/c++/*/iostream

You might try yum provides "*/iostream" to see which packages have it (be prepared for lots of choices).

You might want to use locate or find to see what copies of iostream are on the system.

After reading the first post more carefully, I think the OP is using g++ version 3.3 (both 3.3 and 4.3 seem to be installed) but libstdc++33-devel is not installed.

Maybe get rid of gcc3.3 to avoid confusion. Maybe use the right path to get g++ version 4.3. Maybe (but probably not the best choice) install libstdc++33-devel so g++ version 3.3 can find its header files.

Last edited by johnsfine; 01-11-2010 at 05:49 PM.
 
Old 01-11-2010, 06:15 PM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2020 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,325

Rep: Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583
rpm -qf /usr/include/c++/4.3/iostream
The reply = libstdc++43-devel-4.3.3_20081022-9.5 i.e. libstdc++43-devel

g++ code.cpp

./a.out
Ingresa tu edad:

No, I don't see any problems in Suse 11.1 ..

find /usr/include/c++/ -name iostream
/usr/include/c++/3.3.3/iostream
/usr/include/c++/4.1.3/iostream
/usr/include/c++/4.3/iostream

g++-3.3 code.cpp : works too.
( g++-4.1 code.cpp : also OK.)
.....

P.S. : No 'yum' in Suse. The Yast2 command line tool is 'zypper'.
.....

Last edited by knudfl; 01-11-2010 at 06:33 PM.
 
Old 01-11-2010, 06:22 PM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by johnsfine View Post
You might try yum provides "*/iostream" to see which packages have it (be prepared for lots of choices).
...the OP probably doesn't have yum, but you should have zypper...or could use yast

It looks as if iostream is provided by boost (two variants on my system, but I don't know anything about which to choose...I suspect for this instance it makes no discernible difference) and/or libstream and/or libskstream. Ensure that you have at least one of those and that locate shows a path that you can work with.
 
Old 01-11-2010, 06:27 PM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2020 CentOS6.10 CentOS7.7 + 50+ other Linux OS, for test only.
Posts: 17,325

Rep: Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583
@ salasi
Quote:
It looks as if iostream is provided by boost
I can't image a boost header will work for this. ?

See post # 6 for the c++ headers.
 
Old 01-11-2010, 06:36 PM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by knudfl View Post
find /usr/include/c++/ -name iostream
/usr/include/c++/3.3.3/iostream
/usr/include/c++/4.1.3/iostream
/usr/include/c++/4.3/iostream

g++-3.3 code.cpp : works
You have /usr/include/c++/3.3.3/iostream on your system. I guessed that the OP does not have that file (but does have a 4.3 copy of iostream).

The OP checking what g++ he is using and what iostream he actually has, would be much more meaningful than my guessing.

Quote:
P.S. : No 'yum' in Suse.
I stand corrected. I hope I'll remember that next time (but probably I'll fail to remember). I hope that detail in my post did not confuse the OP.

The copies of iostream etc. used on my own systems are not in subdirectories of /usr/include/ so I didn't want to completely assume the OP's copy of g++ is configured to look in /usr/include/c++/version/. However, that is by far the most likely place for g++ to be configured to look for iostream.
 
Old 01-12-2010, 08:02 AM   #10
jmalbornoz
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your kind replies. I have gathered this from g++ -v mycpp and your posts:

My system runs gcc 2.8.1. I need to work on some old Fortran77 codes and the gcc version that the system came with (a recent one, can't remember the exact version) was giving me a lot of trouble due to obsolescent statements under Fortran90, so I installed this old gcc version and my Fortran problems were gone. Now g++ -v mycode.cpp tells me that a lot of files are not where they are suppossed to be; I tried copying the files that g++ can't find to the directories in its search path, but so far it seems to me a very poor and naive way around this problem.

Now the thing is that I really need to keep working on these old Fortran codes, but at the same time I need to learn C++. Our resident guru told me to come back once I finished working in Fortran to re-install everything from scratch, however I would like to learn my way around Linux and stop pestering the guy!

Cheers

Joe
 
Old 01-12-2010, 10:04 AM   #11
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
gcc is designed to allow multiple versions to be installed and usable at the same time.

There are a few different ways it might be configured to let you specify version.

Try ls -l /usr/bin/g++* to find files that might be set up for one common way of letting you use multiple versions of g++.

Maybe you can use the version specific name of g++ to learn C++.

Or maybe, you can rename the obsolete g++ to a version specific name and then create a soft link as /usr/bin/g++ pointing to the copy that should be current.
 
1 members found this post helpful.
Old 01-12-2010, 12:27 PM   #12
jmalbornoz
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Bingo! Using s -l /usr/bin/g++* was the solution!

PHP Code:
jm@linux-qmfq:~> ls -/usr/bin/g++*
lrwxrwxrwx 1 root root      7 2009-03-16 12:34 /usr/bin/g++ -> g++-4.3
-rwxr-xr-x 1 root root 216420 2008-12-02 23:59 /usr/bin/g++-4.3 
I compiled my code succesfully with g++-4.3

Thanks again!

Joe
 
Old 01-12-2010, 02:27 PM   #13
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
That ls output was surprising given everything you said before.

I expect the surprise might be explained by the output of

which g++
 
  


Reply

Tags
c++, suse


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
can not compile c/c++ programs on suse 9.1 harrypotter Linux - Newbie 6 02-17-2008 07:57 AM
Can't compile on SUSE 9.3 TallGuy Linux - Software 3 08-07-2005 05:12 PM
kernel compile in suse-9.3? greythorne SUSE / openSUSE 3 06-28-2005 04:01 AM
gnucash 1.8.9 will not compile in suse 9.0 dsitton Linux - Software 4 05-25-2004 05:44 PM

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

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