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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:17:41+00:00 2026-05-22T17:17:41+00:00

everyone, I have this snippet of the code, and also I have an error:

  • 0

everyone, I have this snippet of the code, and also I have an error:

CC = gcc
SRCS_L = a.c b.c c.c d.c
OBJS_L = a.o b.o c.o d.o
SRCS_R = x.c y.c
OBJS_R = x.o y.o
LIBRARY = lib.a
PROG = prog
FLAGS = -c -D_GNU_SOURCE
CLEAN = clean

all: $(LIBRARY) $(PROG) $(CLEAN)
$(LIBRARY): $(OBJS_L)
    $(CC) $(FLAGS) $(SRCS_L) -lpthread
    ar -r lib.a $(OBJS_L)
$(PROG): $(OBJS_R)
    $(CC) $(FLAGS) $(SRCS_R) -lpthread lib.a
    $(OBJS_R) -o $(PROG) 

$(CLEAN):
    rm -rf *.o 

can somebody tell me what am I doing here wrong?
I receive an error which tells me that it is impossible to make second target (PROG) and also can’t make c.o, why?
thanks in advance

edited

-lpthread - I'm trying to link library
  • 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-22T17:17:42+00:00Added an answer on May 22, 2026 at 5:17 pm

    I’ve upvoted Banthar’s answer, but on a side note I thought I’d mention that using substitution for your object files will make your Makefile less error-prone.

    For example:

    SRCS_L = a.c b.c c.c
    OBJS_L = $(SRCS_L:.c=.o)
    

    OBJS_L will always be a list of object files for the sources defined in SRCS_L.

    For the -lpthread problem:

    Only link to libraries when creating your executable.

    Original:

    $(CC) $(FLAGS) $(SRCS_R) -lpthread lib.a
    $(OBJS_R) -o $(PROG) 
    

    Fixed:

    $(CC) $(FLAGS) $(SRCS_R) lib.a
    $(CC) -lpthread $(LIBRARY) $(OBJS_R) -o $(PROG) 
    

    Also, I highly recommend separating your executable and library into separate Makefiles. Doing so will allow you to move and reuse your library more easily and simplify the logic of your Makefiles.

    For instance:

    LIBRARY=my_lib.a
    CC=gcc
    SOURCES=$(wildcard *.c)
    OBJECTS=$(SOURCES:.c=.o)
    CFLAGS=-c -g -Wall
    
    build: $(OBJECTS)
        ar rcs $(LIBRARY) $(OBJECTS)
    clean:
        rm -rf $(LIBRARY) $(OBJECTS)
    
    rebuild: clean build
    
    $(OBJECTS):
        $(CC) $(CFLAGS) $(@:.o=.c) -o $@
    

    Using a Makefile for you library as the one above means that you do not have to edit the Makefile whenever you add or remove a source file. Make note, however, that you will need to dedicate a separate directory for your library for Makefiles such as this to work properly.

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

Sidebar

Related Questions

hello everyone I have this snippet of the code: local helper(f, i, j) =
hello everyone I have this snippet of the code: local fun NTimesF(f, n:int) =
hello everyone I have this snippet of the code: void* Init(int N) { Hand
everyone, I have this piece of the code: void foo(int var, int var1) {
Thanks to everyone out there helping newbies like me. So far I have this:
Thanks everyone for taking the time to read this. I have styled my navigation
Now I do have a hw question for everyone...I've been staring at this for
Hello everyone i currently have this: import feedparser d = feedparser.parse('http://store.steampowered.com/feeds/news.xml') for i in
i have this html code. Im using Simple HTML Dom to parse the data
I have this block of code to read in the ISO 8601 Date/Time specification.

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.