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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:45:39+00:00 2026-05-26T09:45:39+00:00

I have one helper file included in two main files which are built into

  • 0

I have one “helper” file included in two “main” files which are built into two executables with the same makefile. I have debug print statements in the helper file. I want the print statements to actually be printed in one executable, but not the other. Is there a way to do it? Right now I have the following, and I was hoping to compile with DEBUG_PRINT defined for one executable but not the other, but I don’t see how.

main1.cpp:

    #include "helper.h"
    ...

main2.cpp:

    #include "helper.h"
    ...

helper.cpp:

    #ifdef DEBUG_PRINT
    cout << "here is a debug message" << endl;
    #endif

Makefile:

    build: main1 main2
    main1: main1.o helper.o
        g++ -g -o main1 main1.o helper.o
    main2: main2.o helper.o
        g++ -g -o main2 main2.o helper.o
    %.o: %.cpp
        gcc -g -c $<

  • 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-26T09:45:40+00:00Added an answer on May 26, 2026 at 9:45 am

    You will need two different object files (main1-helper.o and main2-helper.o) and target-specific compiler flags:

     main1: CXXFLAGS=-DDEBUG_PRINT
     %.o: %.cpp
          gcc $(CXXFLAGS) -g -o $@ -c $<
    

    Note: This leaves you with the problem of generating main1-helper.o from helper.o. There are a few ways to solve this; however, you might be more comfortable using automake from the start instead of rolling your own solutions.

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

Sidebar

Related Questions

have one time consuming step that flattens a bunch of files. basically i'd like
I have one folder synced between two computers (using one of online sync tools).
I have one database table which contains 8 columns. One of the columns is
I have the following two ActiveRecord queries in an application_helper.rb file: @left_menu = Page.select('id,
I have helper class which contain different methods. I dо not want to include
I have one table having ID and other attributes. How can I get list
I have one project with is developed in Php and javascript. How to open
I have one table that has sales records and another table that has additional
I have one doubt regarding casting. public void Test(out T a, out T b)
I have one form with several text fields and one button. When i enter

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.