|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
Btw,that has nothing to do with GCC,that's the C++ syntax,otherwise you would have to write std::cout every time.
|
|
#6
|
||||
|
||||
|
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. |
|
#7
|
||||
|
||||
|
Quote:
|
|
#8
|
|||
|
|||
|
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 |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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...
|
|
#11
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > c++ devel in linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|