Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Steps in compiling a c++ program in LINUX

Posted on 2000-02-23
4
Medium Priority
?
194 Views
Last Modified: 2010-04-22
My Context:
I have learned ANSI C++ in the Codewarrior IDE on windows.
I run a Mandrake LINUX but am thinking of going to Slackware
(its been mentioned as a good learning source)

My Question:
How do I get from a source/header files to an executable?

(how do I run the compiler, is it always present
 Is there a directory I need to be in, where will my files end up
 Is there an IDE for LINUX, and anything else I need to code . . . )

0
Comment
Question by:rhik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
mattrope earned 100 total points
ID: 2553124
Linux generally comes with g++, which is the Gnu C++ compiler.  To compile a program with just a couple of files, you could do this:

g++ -o desired_final_executable_name file1.C file2.C . . .

For large programs, it is better to compile the .C files separately into object (.o) files and then link the object files together.  This can be done as follows:

g++ -c file1.C          (creates file1.o)
g++ -c file2.C          (creates file2.o)

g++ -o final_executable_name file1.o file2.o . . .


Obviously typing each of these commands each time you want to compile and test your program would be very tedious, so it is possible to create a file called a "Makefile" which contains all the dependency information for your project and specifies exactly what files are needed to build the final executable.  The syntax of makefiles is too complex to post here, but you can find lots of info on the Internet.  Basically having a makefile allows you to type "make" and your computer will figure out which source files have changed, only recompile the ones necessary, and build the final executable.

Hope this is what you were looking for...
0
 

Author Comment

by:rhik
ID: 2560127
#include <iostream>
#include <string.h>
void main()
{
      cout <<"hello world";

}
 
the above  gives me an error.
" Parse error before '}' "
0
 

Expert Comment

by:Remote040300
ID: 2681322
The standard library is defined in a namespace called standard. So, your code should read either:

#include <iostream>
#include <string.h>
void main()
{
std::cout <<"hello world";
}

or (better)

#include <iostream>
#include <string>
using namespace std;

void main()
{
cout <<"hello world";
}

(Stroustrup, C++ Programming Language, Special Edition, pg. 46,47)

I don't see why you should include string or string.h in the above.

Note that it's supposed to be:
int main()
but I don't think this will cause your compiler to report an error. Still, stick to int and return a value to the system (zero if everything goes fine).
0
 

Author Comment

by:rhik
ID: 2790388
Thankyou and good answer.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question