Solved

Make file for a program that has a main function taking command line arguments

Posted on 2004-04-29
7
201 Views
Last Modified: 2011-09-20
Hi all!

I have a program with a main function that takes command line arguments.

It looks like

int main(int argc, char ** argv) {
// code here
}

I want to write a makefile that generates an executable for this program called myprog. When I run this program I want to be able to give command line arguments to the main function.

What do I need in my makefile for doing this? I can write a makefile for a program that takes no arguments but I dont know how to write the makefile in this case.

Thanks in advance!

0
Comment
Question by:manad
7 Comments
 
LVL 8

Accepted Solution

by:
_corey_ earned 34 total points
ID: 10953921
The makefile should not make a difference.

You simply provide the paramaters at runtime.

yourprogram param1 param2

0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 33 total points
ID: 10953965
If you're using VC++ 6.0, you can make this setting by pressing Alt-F7, and then click the DEBUG tab, and fill in Program-Argument field.

What compiler are you using, and what's your OS?
0
 

Author Comment

by:manad
ID: 10954397
I am using g++ for compilation on Sun-Solaris platform.

So basically if the target is called 'myprog' then all I need to do for running the program is...

myprog param1 param2

Is this correct?


0
 
LVL 3

Assisted Solution

by:CoolBreeze
CoolBreeze earned 33 total points
ID: 10956195
yup, if I am not wrong.
and yes, the makefile should be the same.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to convert c++ code to Android App 3 108
Grammars for C C++ and java 1 131
Compile GLUT with Visual Studio 2015 1 174
How to Correctly derive class from CWinThread in MFC 4 66
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

839 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