Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:42:08+00:00 2026-06-09T22:42:08+00:00

I have a C file for which I want to give cmd line arguments.

  • 0

I have a C file for which I want to give cmd line arguments.

Say

$ make --argument1 

or something like this.

So that in my main program I should be able to do argv[1] and be able to access the variable.

I have tried looking for ways of doing this. Is there actually a way of doing this?

These were the relevant content I found on the GNULinux manual about make.

variables defined on the command line are passed to the sub-make
through MAKEFLAGS. Words in the value of MAKEFLAGS that contain ‘=’,
make treats as variable definitions just as if they appeared on the
command line.

Is this what I need to read up more or is this in a different context?

Do let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:42:10+00:00Added an answer on June 9, 2026 at 10:42 pm

    I think you misunderstand the use of command line arguments – they are given when the executable is executed not when it is compiled.

    Better example

    foo.c

    #include <stdio.h>
    
    int main()
    {
       int myval=DEFVAL;
    
       printf("myval=%d\n", myval);
       return 0;
    }
    

    Makefile

    DEFVAL=17
    
    foo: foo.c
       gcc -DDEFVAL=${DEFVAL} foo.c -o $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this file file.txt which I want to split into many smaller ones.
I have an SQL file which will give me an output like below: 10|1
I have a 200MB file that I want to give to a user via
I have a FTP with some file which I want give it to the
I have a .ipa file which i want to test in iPad before submitting
I have a text file which I want to filter using awk. The text
I have a MySQL file which I want to import via PHP 5. In
I have a binary file to which I want to append a chunk of
I have a huge text file which I want to explode into an array.
I have an array of file names which I want to download. The array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.