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

  • Home
  • SEARCH
  • 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 3876416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:22:45+00:00 2026-05-19T22:22:45+00:00

It is my understanding that C has makefiles and include statements so you don’t

  • 0

It is my understanding that C has makefiles and include statements so you don’t have singular monster size files and that you should functionally decompose your code. Therefore, if I’m right, I should be able to make functional calls across .c files if I do my headers and makes correctly.

I’m trying to do that but unfortunately I am getting an error.

The files have the following contents:

File 1)test.c:

#include<stdio.h>
#include"suc.h" 

main()
{
    printf("Hello World\n\n");
    printf("This is the number: %d \n\n", suc(6));
}

File 2)makefile:

CC=gcc
CFLAGS=-c -Wall

test: suc.o
$(CC) -Wall -o test test.c

suc.o: suc.c
$(CC) $(CFLAGS) suc.c

File 3)suc.h

#ifndef SUC_H_GUARD

#define SUC_H_GUARD

// returns the successor of i (i+1)
int suc(int i);


#endif

File 4)suc.c

#include "suc.h"

int suc(int i)
{
return i + 1;
}

When I make (make -B) the top I get:

gcc -c -Wall suc.c
gcc -Wall -o test test.c
test.c:7: warning: return type defaults to 'int'
/tmp/cc/7w7qCJ.o: In function 'main':
test.c: (.text+0x1d): undefined reference to 'suc'
collect2: ld returned 1 exit status
make: *** [test] Error 1

However:
Both produce the expected results:
A) This single file program works ok!

#include<stdio.h>

main()
{
    printf("Hello World\n\n");
printf("This is the number: %d \n\n", suc(6));
}

int suc(int i)
{
return i + 1;
}

B) All the files in the original but with the following change to test.c:

#include<stdio.h>
#include"suc.h" //suc() is still defined b/c suc.h is included

main()
{
    printf("Hello World\n\n");
printf("This is the number: %d \n\n", 4); //HERE! -> no function call
}

Help, please and thank you!
I don’t quite understand what the error messages are trying to tell me.

  • 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-19T22:22:46+00:00Added an answer on May 19, 2026 at 10:22 pm

    You need to separately compile the source files to their object files and then link the object file to get the executable test.

    So you need:

    CC=gcc
    CFLAGS=-c -Wall
    
    test: test.o suc.o
    <tab>$(CC) -Wall -o test test.o suc.o
    
    test.o: test.c
    <tab>$(CC) $(CFLAGS) test.c
    
    suc.o: suc.c
    <tab>$(CC) $(CFLAGS) suc.c
    

    where <tab> is a tab.


    The problem in your current makefile is here:

    test: suc.o
        $(CC) -Wall -o test test.c
    

    which says test depends on suc.o and to get test you need to do:

    $(CC) -Wall -o test test.c
    

    but look at that compile/link line, it does not include any source/object file that has the suc function defined.

    You can add a suc.o as:

    $(CC) -Wall -o test test.c suc.o
    

    But it is considered bad because say you change only suc.c file then your makefile will regenerate suc.o and will also have to regenerate test, but for regenerating test you are re-compiling test.c even thought it was not changed.

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

Sidebar

Related Questions

No related questions found

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.