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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:12:42+00:00 2026-06-13T01:12:42+00:00

I got a C++ program for which someone else made a make file. I

  • 0

I got a C++ program for which someone else made a make file. I want to compile the program with flag -g, but I don’t know where to add it. Below is the make file.

CC = g++
LOADLIBES = -lm
CFLAGS = -Wall -O2


SRC1 = Agent.cpp Breeder.cpp CandidateSolution.cpp \
    Cupid.cpp FateAgent.cpp Grid.cpp Reaper.cpp \
    fitness.cpp

SRC2 = main.cpp

SRC  = $(SRC1) $(SRC2)

OBJS = $(SRC1:.cpp = .o)

AUX = $(SRC1:.c = .h)


main: $(OBJS) 
#   $(CC) $(CFLAGS) -o $(SRC) $(AUX) 

.PHONY: clean
clean:
    rm -f *.o main

Where should I add that I want to use -g?

  • 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-13T01:12:43+00:00Added an answer on June 13, 2026 at 1:12 am

    $(CC) is used for compiling C programs. $(CXX) is used for compiling C++ programs. Similarly $(CFLAGS) is used for C programs, $(CXXFLAGS) is used for compiling C++.

    Change the first few lines to this:

    #CC = g++
    LOADLIBES = -lm
    CXXFLAGS = -Wall -O2 -g
    

    (But see others’ notes about incompatibilities between -O2 and -g.)

    Get rid of the spaces inside the parentheses in this line:

    OBJS = $(SRC1:.cpp=.o)
    

    Change the main lines to this:

    main: $(OBJS) $(SRC2)
    #   Built by implicit rules
    

    The resulting makefile should look like this:

    #CC = g++
    LOADLIBES = -lm
    CXXFLAGS = -Wall -O2 -g
    
    
    SRC1 = Agent.cpp Breeder.cpp CandidateSolution.cpp \
        Cupid.cpp FateAgent.cpp Grid.cpp Reaper.cpp \
        fitness.cpp
    
    SRC2 = main.cpp
    
    SRC  = $(SRC1) $(SRC2)
    
    OBJS = $(SRC1:.cpp=.o)
    
    AUX = $(SRC1:.c=.h)
    
    main: $(OBJS) $(SRC2)
    #   Built by implicit rules
    
    .PHONY: clean
    clean:
        rm -f *.o main
    

    and the output should look like this:

    $ make
    g++ -Wall -O2 -g   -c -o Agent.o Agent.cpp
    g++ -Wall -O2 -g   -c -o Breeder.o Breeder.cpp
    g++ -Wall -O2 -g   -c -o CandidateSolution.o CandidateSolution.cpp
    g++ -Wall -O2 -g   -c -o Cupid.o Cupid.cpp
    g++ -Wall -O2 -g   -c -o FateAgent.o FateAgent.cpp
    g++ -Wall -O2 -g   -c -o Grid.o Grid.cpp
    g++ -Wall -O2 -g   -c -o Reaper.o Reaper.cpp
    g++ -Wall -O2 -g   -c -o fitness.o fitness.cpp
    g++ -Wall -O2 -g    main.cpp Agent.o Breeder.o CandidateSolution.o Cupid.o FateAgent.o Grid.o Reaper.o fitness.o -lm  -o main
    

    For completeness, this is the version of make I am using on Ubuntu 10.04:

    $ make -v
    GNU Make 3.81
    Copyright (C) 2006  Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.
    
    This program built for i486-pc-linux-gnu
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile a c++ program that I got from someone else. It's
I'm a newbie and I know that this C program which I got somewhere
I've got a program made basically from a ListCtrl and has an add button,
I got a C# program which opens a EventWaitHandle like this to get triggered
I got the program for Wifi tethering which i got a open (non secured)
I've got a program that takes 3 arrays (which are the same length, can
What I got: I got a textual representation which my program converts to a
I'm trying to compile someone else's project, and I'm getting about 850 errors all
Hello I've currently got a program which retrieves WMI information and stores it to
I made a program which is still in development. I did not declared main

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.