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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:41:12+00:00 2026-05-31T09:41:12+00:00

I wanted to write a makefile for a program that has source files located

  • 0

I wanted to write a makefile for a program that has source files located in different directories, the structure is:

--root(here will be makefile)    
  --src:
    --main.c
    --include:
      --here are 6 .h files, that are used by other .c files, main.c includes on all of them
    --operacje
      --suma.c
      --iloczyn.c
      --roznica.c
    --reszta:
      macierz.c
    --we_wy:
      --rest of the .c files

most of .c files include at least one .h file. This is what I wrote so far:

VPATH=./src:./src/include:./src/operacje:./src/reszta:./src/we_wy
CLFAGS = -Wall
CC = gcc
INCLUDE = -I src/include
NAME = macierze

FILE_SOURCE := pliki.c wczytaj_plik.c wypisz_plik.c
CONSOLE_SOURCE := wczytaj_konsola.c wypisz_konsola.c
OTHER_SOURCE := suma.c roznica.c iloczyn.c macierz.c
HEADERS := suma.h roznica.h iloczyn.h wypisz.h wczytaj.h macierz.h

FILE_OBJECTS := $(FILE_SOURCE:.c=.o)
CONSOLE_OBJECTS := $(CONSOLE_SOURCE:.c=.o)
OTHER_OBJECTS := $(OTHER_SOURCE:.c=.h)

%.o: %.c %.h
    gcc $(CFLAGS) $(INCLUDE) -c $?

%.o: %.c
    gcc $(CFLAGS) $(INCLUDE) -c $? -o $@


finput: HEADERS+=pliki.h

finput: $(FILE_OBJECTS) $(OTHER_OBJECTS) main.o
    gcc $(CFLAGS) -o $(NAME) $^ -D WEWY_PLIKI 

main.o: main.c $(HEADERS)
    gcc $(CFLAGS) $(INCLUDE) -c src/main.c

clean: 
    rm -rf *.o

The goal is, to make compiled program run a bit differently based on make , hence the -D option and adding

finput: HEADERS+=pliki.h

this finput is the first of the 4 possible options. Each option will be using slightly different set of .c and .h files

Now, when I do

make finput

i get the listing:

gcc  -I src/include -c ./src/we_wy/pliki.c ./src/include/pliki.h
gcc  -I src/include -c ./src/we_wy/wczytaj_plik.c -o wczytaj_plik.o
gcc  -I src/include -c ./src/we_wy/wypisz_plik.c -o wypisz_plik.o
gcc  -I src/include -c src/main.c
gcc  -o macierze pliki.o wczytaj_plik.o wypisz_plik.o ./src/include/suma.h ./src/include/roznica.h ./src/include/iloczyn.h ./src/include/macierz.h main.o -D WEWY_PLIKI 
wczytaj_plik.o: In function `wczytaj':
wczytaj_plik.c:(.text+0x5f): undefined reference to `macierz_alokuj'
main.o: In function `main':
main.c:(.text+0x7e): undefined reference to `suma'
<and other undefined references in main>

I noticed few errors:
1. it doesen’t produce .o files from $(OTHER_OBJECTS)
2. there is no -Wall option from $(CFLAGS)
3. and of course it doesen’t complete.

I would be grateful for some info, what am I doing wrong.

  • 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-05-31T09:41:13+00:00Added an answer on May 31, 2026 at 9:41 am

    OTHER_OBJECTS := $(OTHER_SOURCE:.c=.h)

    If this is not a typo, it is the explanation for (1.). You rename the files to header files, and the header files are found in VPATH and have no remake rules, so they are included verbatim in $^. Try $(OTHER_SOURCE:.c=.o).

    CLFAGS = -Wall

    Try CFLAGS instead.

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

Sidebar

Related Questions

I wanted to write a program that test if two files are duplicates (have
Say I wanted to write a program that would export calendar data so that
I wanted to write if/for each statement that will get me all the child
I wanted to write a timer in java.which will do the following: when program
I wanted to write a javascript code that will slide a div in specific
I wanted to write a program that converts a decimal in to binary. For
I'm a beginner in C++ Programming language. I wanted to write a program that
I wanted to write a program which writes to multiple files simultaneously; thought it
I wanted to write a small Rapid Serial Visual Presentation (RSVP) program for my
I wanted to write a function that would take an object and convert it

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.