Solved

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

Posted on 2004-04-29
7
198 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now