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 8808495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:38:16+00:00 2026-06-14T02:38:16+00:00

I have a source file test.c and its header test.h , a file main.c

  • 0

I have a source file test.c and its header test.h, a file main.c and the makefile.
I want to set up my makefile so that it (1) compiles test.c to build an executable test.o,
and (2) compiles test.c to print the assembly code to test.s using -S flag.

I have tried to set up the makefile as I thought would be correct, but this of course doesn’t actually run the last test.s line.

FLAGS = -c -Wall
CC = gcc
ASM = -S

all : optimize
optimize: main.o test.o
    $(CC) main.o test.o -o optimize
main.o: main.c test.h
    $(CC) $(FLAGS) main.c
test.o: test.h test.c
    $(CC) $(FLAGS) test.c
test.s: test.h test.c
    $(CC) $(ASM) -Wall test.c

Can anyone tell me how I should have structured this differently, to create both test.s and test.o?

I tried to change the optimize: line and the following one to:

optimize: main.o test.o test.s
    $(CC) main.o test.o test.s -o optimize

but the linker gave an error multiple definition of 'test'.

  • 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-14T02:38:17+00:00Added an answer on June 14, 2026 at 2:38 am

    Simply add test.s to the line that starts with optimize:.

    What this does is add the rule test.s to the dependencies of the optimize line.

    You could also add it to the all line, as suggested by Vaughn Cato.

    It’s important to know that there is a difference between the rule test.s and the file test.s

    You can put anything you want as the name of the rule, but by convention you normally just use the filename.

    Here’s an example Makefile that will do what you want. I put the dep under all so you can just make asm and I also changed the rule name to asm for clarity.

    FLAGS = -c -Wall
    CC = gcc
    ASM = -S
    
    all : optimize asm
    optimize: main.o test.o
        $(CC) main.o test.o -o optimize
    main.o: main.c test.h
        $(CC) $(FLAGS) main.c
    test.o: test.h test.c
        $(CC) $(FLAGS) test.c
    asm: test.h test.c
        $(CC) $(ASM) -Wall test.c -o test.s
    

    Finally, because you seem a bit shaky on how Makefiles work, (I don’t blame you honestly), I suggest reading this tutorial: http://mrbook.org/tutorials/make/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a source file that is 18218 bytes. I open the file
I have a source XML file that is used to create C# files that
I have a large source file in Perforce that has been split up into
Suppose I have two lists that holds the list of source file names and
As the title says, I want to have a build tool that quite much
I am trying to test a method that copies a source file to a
I have a source file, openpage.pl, where I call use_module/1 to import SWI-Prolog's http_open/3:
I have a source file where 2 features have been added. In order to
Suppose I have a source file open and I launch a shell. I can
Referring here A is a precompiled Java class (I also have the source file)

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.