How to compile and execute C++ and Java in Fedora 11 and Ubuntu 9.10?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to compile and execute C++ and Java in Fedora 11 and Ubuntu 9.10?
I have installed Fedora 11 and Ubuntu 9.10 and have instaled development packages(gcc,gc++,..) in both i am able to compile and execute c programs but when it comes to c++ i get an error...
i ve tried using cc & gcc..
how can i over come this??
[temp@satheesh Documents]$ vi sam.cpp
#include<iostream>
main()
{
cout<<"Welcome\n";
}
[temp@satheesh Documents]$ cc sam.cpp
sam.cpp: In function ‘int main()’:
sam.cpp:4: error: ‘cout’ was not declared in this scope
[temp@satheesh Documents]$ vi sam.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
[temp@satheesh Documents]$ ll
total 8
-rwxr-xr-x. 1 temp temp 49 2009-11-18 14:33 sam.cpp
-rwxr-xr-x. 1 temp temp 118 2009-11-18 14:46 sam.java
[temp@satheesh Documents]$ java sam.java
Exception in thread "main" java.lang.NoClassDefFoundError: sam/java
Caused by: java.lang.ClassNotFoundException: sam.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
Could not find the main class: sam.java. Program will exit.
[temp@satheesh Documents]$
Well cout is part of the std library of C++. And everything in it is in the std namespace. If you don't have "using namespace std" you can use std::cout instead of cout.
As for Java, you have to compile the Javaprogram using javac. And then you need Java sdk or jdk, not just the jre. The javac compiler will make a .class file you can run.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.