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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:51:52+00:00 2026-06-02T07:51:52+00:00

I have the following makefile CXX = g++ CXXFLAGS = -c -g -pg -Wall

  • 0

I have the following makefile

CXX       = g++
CXXFLAGS  = -c -g -pg -Wall -Wextra
LINK      = g++
TARGET    = ../../Binaries/tests
SOURCES   := ../Src/$(wildcard *.cpp)
OBJS_DIR  := ../Objects
OBJS      = $(sort $(patsubst %.cpp, $(OBJS_DIR)/%.o, $(patsubst %.c, $(OBJS_DIR)/%.o, $(notdir $(SOURCES)))))

tests: $(TARGET)

$(TARGET): $(OBJS)
  $(LINK) $? -o $@

$(OBJS): $(SOURCES)
  $(CXX) $(CXXFLAGS) $? -o $@

which, when run using make tests (or simply just make), gives the following output:

g++  -o ../../Binaries/tests
g++: fatal error: no input files
compilation terminated.
make: *** [../../Binaries/tests] Error 4

This seems to me that make is trying to link the files (that don’t yet exist) without checking the rule for $(OBJS). My goal is to have a Makefile that is entirely self sufficient, being able to find the *.cpp file in ../Src and the *.o file (that it will generate itsef) in ../Objects, however the rule I’ve written doesn’t seem to be working out that way. Can anyone please tell me where I’ve gone wrong here?

  • 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-02T07:51:54+00:00Added an answer on June 2, 2026 at 7:51 am

    Most likely, the problem is on the following line:

    SOURCES   := ../Src/$(wildcard *.cpp)
    

    It should be something like this instead:

    SOURCES   := $(wildcard ../Src/*.cpp)
    

    Also transforming sources into objects could be rewritten as follows:

    OBJS      := $(SOURCES:../Src/%.cpp=$(OBJS_DIR)/%.o)
    

    Finally the compilation rule is usually implemented through pattern rules:

    $(OBJS_DIR)/%.o : ../Src/%.cpp
        $(CXX) $(CXXFLAGS) $< -o $@
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of makefile: CXXFLAGS = -std=c++0x -Wall SRCS = test1.cpp
I have the following Makefile rules: DIR = src SOURCES = $(shell find $(DIR)
I have the following makefile CXXFILES = pthreads.cpp CXXFLAGS = -O3 -o prog -rdynamic
I have the following PHONY target in Makefile install: echo /usr/bin/shelldecrypt must be writable
I have used -Wall -Werror in my Makefile but I want to disable following
I am experimenting with makefile...mainly when sources are in many directories I have following
I have the following Makefile.am inside ./src where I need to generate dependencies for
I currently have the following rule in a Makefile: ../obj/%.o: %.cpp mkdir -p ../obj/$<
I have the following makefile (fragment) SRC_DIR = src OBJ_DIR = obj DEP_DIR =
In a makefile, I have the following line: helper.cpp: dtds.h Which ensures that helper.cpp

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.