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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:41:27+00:00 2026-06-02T04:41:27+00:00

My makefile looks as follows program_NAME := myprogram program_C_SRCS := $(wildcard *.cc) program_C_OBJS :=

  • 0

My makefile looks as follows

program_NAME := myprogram
program_C_SRCS := $(wildcard *.cc)
program_C_OBJS := ${program_C_SRCS:.cc=.o}
program_OBJS := $(program_C_OBJS) 
program_INCLUDE_DIRS := ../INCLUDE
program_LIBRARY_DIRS := 
program_LIBRARIES :=
CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))
LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))
LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))

.PHONY: all clean distclean

all: $(program_NAME)

$(program_NAME): $(program_OBJS)
$(LINK.cc) $(program_OBJS) -o $(program_NAME)

clean:
    @- $(RM) $(program_NAME)
    @- $(RM) $(program_OBJS)

distclean: clean

I have created a library stack.a in some path /home/Desktop/kk/stack.
I want to include this library into my makefile so that during linking it should be picked up from that path.

I tried to give:

program_LIBRARY_DIRS := /home/Desktop/kk/stack

and in linking step I gave:

$(LINK.cc) $(program_OBJS) stack.a -o $(program_NAME)

But the makefile is not able to pick up the library from the path mentioned.

Instead, if I directly give:

$(LINK.cc) $(program_OBJS) /home/Desktop/kk/stack/stack.a -o $(program_NAME)

it works perfectly.

Please help me how to include this library path so that I do not have to give the location of library in link command.

  • 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-02T04:41:29+00:00Added an answer on June 2, 2026 at 4:41 am

    The -L link option only applies to libraries named libX.a or libX.so and linked using -lX, for some string X. You would need to rename stack.a to libstack.a and refer to it in the link command as -lstack.

    (You should also, ideally, put that in the program_LIBRARIES definition and use that in the $(LINK.cc) line.)

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

Sidebar

Related Questions

I have a Makefile that looks like this CXX = g++ -O2 -Wall all:
I have a Makefile that looks something like this: sometarget: command_one # calls fork()
I have a makefile that looks like: default: lua blah.lua Now, in Vim, I
I m writing a simple Makefile which looks like this CC=gcc CXX=g++ DEBUG=-g COMPILER=${CXX}
My project directory looks like this: /project Makefile main /src main.cpp foo.cpp foo.h bar.cpp
I have a Makefile.am file right now that looks like this: lib_LIBRARIES = foo.a
I wrote a small makefile which follows the general structure, creating object files and
part of my makefile looks like this ... ifdef vis flg += -framework GLUT
I'm trying to specify rpath in my binary. My makefile looks like this- CC=gcc
My source and build tree looks like this (see Makefile to put object files

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.