Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 66
multi threaded debug dll option in visual studio 2 96
Need some help with listview limit text 20 98
I could not build boost code, 10 79
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.
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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now