Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old January 17th, 2003, 07:20 AM
gamgee gamgee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ireland
Posts: 26 gamgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
c++ devel in linux

Im using suse 8.1, but having always used windows, I am finding linux quite frustrating.

First of all, I cannot seem to compile almost anything, with g++. It does not seem to recognise iostream commands like cout and cin, though it does not throw an error for including <iostream>. Are there librarys I must include when compiling with g++?

It does compile a simple main fuction that only calls a printf statement. I try to run the compilation with the ./ command but it comes up permission denied. The ./ command seemed to work for me when I was using RedHat 7.1. Is there another command? Or have I some setting that does not let me run files through the console?

I hope the above has made some sense.

I look forward to any advise.

Thanking you in advance,
Samwise Gamgee

Reply With Quote
  #2  
Old January 17th, 2003, 08:56 AM
Tuxie Tuxie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Inside the GNU/Hurd kernel
Posts: 492 Tuxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 7
I have never had problems with iostream and g++,what error does it give?Maybe you could post the code?

You probably haven't set the right permission on the application,check the properties of the application file with your filemanager and make sure that 'Execute' permission is checked.(Maybe you are compiling the application with a diferent user than you are using to run it?)
If the permission is right,you can run every application from a terminal.
./<application file> is the path to the application file.The dot stands for the current directory,so that you execute the application in the current directory.

Reply With Quote
  #3  
Old January 17th, 2003, 10:06 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Code:
#include <iostream>
/* test.c */

using namespace std;

int main() {
        cout << "This is just a test.\n";
        return 1;
}

I know it, simplistic. But it is just for an example.

This was compiled off of RH8.0 using this command: g++ test.cpp
Then it was run by: ./a.out
If you want to give it a name: g++ -o <program name> <source file>

Now, if you remove the using namespace std line from this program, it will not compile and will give errors of not knowing what cout is.
The g++ compile requires you to use a namespace.

Reply With Quote
  #4  
Old January 17th, 2003, 10:19 AM
gamgee gamgee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ireland
Posts: 26 gamgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
of course. that is probably why the cout was not recognised. that still leaves the matter of running outputs eg. a.out. I will check the permissions (im on windows at the mo. - lack of drivers for my wireless card) but I was using the root account, so i doubt that would have been a problem would it?
cheers guys.

Reply With Quote
  #5  
Old January 17th, 2003, 10:27 AM
Tuxie Tuxie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Inside the GNU/Hurd kernel
Posts: 492 Tuxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m
Reputation Power: 7
Btw,that has nothing to do with GCC,that's the C++ syntax,otherwise you would have to write std::cout every time.

Reply With Quote
  #6  
Old January 17th, 2003, 10:31 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
did you compile & run it as root, or just compile it as root?

do a ls -l and see what the results are
example as below
Code:
onslaught@xinstitute ~/temp/test$ ls -l
total 36
-rwxr-xr-x    1 onslaught    dev        12844 Jan 17 10:01 a.out
-rwxr-xr-x    1 onslaught    dev        12844 Jan 17 10:04 test
-rw-r--r--    1 onslaught    dev          104 Jan 17 10:01 test.cpp

This is a directory shot of where I wrote and compiled the test program listed above.

The first two are the compiled executables and the last is the source file.
The permissions on the first two show that the file owner, group and all users can read and execute this file, but only the file owner can write to it.
You might want to change your file permissions on the a.out file to match these. You can always chmod a+x to make it for all people to execute the file.

Reply With Quote
  #7  
Old January 17th, 2003, 10:33 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Quote:
Originally posted by Tuxie
Btw,that has nothing to do with GCC,that's the C++ syntax,otherwise you would have to write std::cout every time.
That is true, it is C++ syntax, but not all compilers require you to state the namespace. In those cases if you don't state it, it defaults to std.

Reply With Quote
  #8  
Old January 17th, 2003, 07:04 PM
gamgee gamgee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ireland
Posts: 26 gamgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok. I can not stating "using namespace std" was the reason for cout not working.
Secondly, the reason I couldnt run the result of the compilation was to do with the permissions, chmod, and that whole rwx-rwx-r x thing. I tried using the chmod to put the in the w in the last category (though i recon it should not have made a diff) but for some reason the permissions never changed. I ended up copying the neccessary files into my home dir - which will do me fine.
Unfortunately now I have hit another snag, simple code that I have compiled easily in windows(bloodshed), throws errors with a description like the following:

/usr/lib/gcc-lib/i486-suse-linux/3.2/.../../../../crt1.0: In function '_start' :
/usr/lib/gcc-lib/i486-suse-linux/3.2/../.././../crt1.0(.text+0x18):undefined reference to 'main'
collect2: ld returned 1 exit status

I apologise that I could not put this problem a little bit more abstractly, but this is all I really have to go on. The code itself does not have a main function, is only an arbitrary data type, of the linked list variety. I was afraid to post its actual contents.

Please Advise,
Thanks once again,
Samwise Gamgee

Reply With Quote
  #9  
Old January 17th, 2003, 07:55 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,829 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 5 m 8 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Ok, at a guess, the reason why you could not change the permissions would be because you did not have the proper rights to do so. I would say it would be easiest to create a directory in your home directory for your testing purposes. You can compile and execute most of them safely enough there.
On your other problem, there is not enough given information to help you on this.

Reply With Quote
  #10  
Old January 17th, 2003, 08:24 PM
gamgee gamgee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ireland
Posts: 26 gamgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ive attached both the header and the cpp. please ignore the commenting as it is out of date. this compiled fine for me in windows, but in linux with g++ , it through the error shown above...
Attached Files
File Type: zip tag_path.zip (973 Bytes, 297 views)

Reply With Quote
  #11  
Old January 19th, 2003, 05:40 AM
gamgee gamgee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ireland
Posts: 26 gamgee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile eureka

In my desparation, I installed an IDE, namely KDevelop. This seems to work. I guess you have to link files (even header files to cpp) in some way for g++. No comes the hard part, getting libxml2 to work . onslaught + tuxie, thankyou both for your time.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > c++ devel in linux


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway