LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   write and run program in fedora (https://www.linuxquestions.org/questions/linux-newbie-8/write-and-run-program-in-fedora-760945/)

monaej 10-10-2009 03:24 AM

write and run program in fedora
 
i have installed fedora on my system but i really dont have any idea how to write a C++ program in fedora and how to compile it .would anybody help regarding this.

foodown 10-10-2009 03:32 AM

For example, I use the command:
Code:

vi test.c
You could, of course, use emacs or any other text editor . . even a GUI text editor like kwrite or gnotepad would work.

And I write this file:
Code:

#include<stdio.h>

int
main (void) {
        printf("Hello, World!\n");
}

And then I can do this:
Code:

adam@hydra5:~$ gcc test.c -o test
adam@hydra5:~$ ./test
Hello, World!
adam@hydra5:~$

Of course, there are LOTS of options that you can pass to gcc, the GNU C Compiler . . . just do a 'man gcc' to see some of them, if not all.

If invoked as 'g++' instead of 'gcc' it will act as a C++ compiler. (You can also invoke it as just 'cc' or 'c++'.)

You don't have to operate purely in the command line like this. There are many development environments for X which are fully featured and have a lot of helpful tools. It is up to you to choose the one that you want. I don't know which is most popular these days, as I don't do a lot of coding.

Good luck!

guyapi 10-10-2009 04:15 AM

Hi,
you might want to try codeblocks . It's Cross platform IDE for Linux, MacOS and Windows. Since I don't use Fedora, I'm not sure if they got it in there repository...
If not you can download it from there site.

greetings, guyapi

monaej 10-20-2009 10:07 AM

can u plz let me know that how to open task manager in fedora 11?

pixellany 10-20-2009 01:56 PM

Quote:

Originally Posted by monaej (Post 3726079)
can u plz let me know that how to open task manager in fedora 11?

I can't tell if this is related to your original question. If this is a new question, then please start a new thread.

Note: Please do not use texting shorthand here:
you, not u
please, not plz

And: Welcome to LQ!!

smeezekitty 10-20-2009 02:58 PM

Quote:

#include<stdio.h>

int
main (void) {
printf("Hello, World!\n");
}
WTF?
how about a code that looks, compiles and works normal?
Code:

#include <stdio.h>
int main(){
  printf("Hello, World!\n");
return 0;
}

i compiled your code in turbo C++ and heres the messages
Code:

Compiling CH.C:
•Error CH.C 3: Declaration syntax error
•Error CH.C 3: ; Expected after "int"
•Warning CH.C 4: main(void) Declaration with no type, int assumed
•Warning CH.C 6: Function should return a value


markush 10-20-2009 03:42 PM

Hello smeezekitty,

Quote:

Originally Posted by smeezekitty (Post 3726388)
WTF?
how about a code that looks, compiles and works normal?

there's nothing wrong with the above code. It's compiled with gcc as it is. But I've never heard that Turbo-C++ runs on Linux.

Markus

gzunk 10-20-2009 04:11 PM

Smeezekitty, It's written in C. Perfectly valid C, and a C++ compiler should compile it.

Here's a C++ version for you

Code:

//===============================================
// Name        : HelloWorldCPlusPlus.cpp
// Author      :
// Version    :
// Copyright  : Your copyright notice
// Description : Hello World in C++, Ansi-style
//===============================================

#include <iostream>
using namespace std;

int main() {
        cout << "Hello World!!!" << endl;
        return 0;
}


smeezekitty 10-20-2009 04:18 PM

Code:

Compiling CPPCODE.CPP:
•Error CPPCODE.CPP 9: Unable to open include file 'IOSTREAM'
 Error CPPCODE.CPP 10: Declaration syntax error
 Error CPPCODE.CPP 13: Undefined symbol 'cout'
 Error CPPCODE.CPP 13: Undefined symbol 'endl'

if i change iostream to iostream.h and comment out using namespace std;
it compiles

markush 10-20-2009 04:21 PM

Hi

Quote:

Originally Posted by smeezekitty (Post 3726471)
if i change iostream to iostream.h and comment out using namespace std;
it compiles

we live in the year of 2009!!! This change in C++ was in 1999 as I remember.

Markus

gzunk 10-20-2009 04:28 PM

Just what version of Turbo C++ are you using? Active development of the product was stopped 15 years ago.

smeezekitty 10-20-2009 04:49 PM

i know that it is version 3.0 for dos dated 1992
i use Turbo C++ and GCC
and i make all my codes so it compiles for both

gzunk 10-20-2009 05:08 PM

Quote:

Originally Posted by smeezekitty (Post 3726507)
i know that it is version 3.0 for dos dated 1992
i use Turbo C++ and GCC
and i make all my codes so it compiles for both

Umm, I really wouldn't. Why don't you use Eclipse CDT + MinGW or Cygwin for your windows development? Then at least you'd have an up to date C++ compiler that complies with the C++98 ISO standard

smeezekitty 10-20-2009 05:11 PM

Quote:

Originally Posted by gzunk (Post 3726515)
Umm, I really wouldn't. Why don't you use Eclipse CDT + MinGW or Cygwin for your windows development? Then at least you'd have an up to date C++ compiler that complies with the C++98 ISO standard

i use that too but some programs need to run on my dos 486 with 12 MB ram

smeezekitty 10-20-2009 05:18 PM

@original poster sorry for the thread hijack, but return type should be on the same line and needed to make that point


All times are GMT -5. The time now is 09:49 PM.