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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:08:34+00:00 2026-06-02T12:08:34+00:00

Need your help with projecting the makefile. So, what I have and what I

  • 0

Need your help with projecting the makefile. So, what I have and what I want to get. I need to build two executables. Source code is common. Preprocessor macros control differences for both exes, for example, in main.cpp:

#if PROJECT_TYPE==FTP
std::cout << "FTP" << std::endl;
#else
std::cout << "SFTP" << std::endl;
#endif

Differences aren’t only in source code but also in additional libraries that used for linking:

FTP_LDFLAGS= -static-libstdc++ -static-libgcc -s -L $(ROOT_DIR)/lib/Release -l:libboost_thread-mgw46-mt-1_49.a -l:libcommon.a \
-l:libfile.a -l:libfilesearcher.a -l:libftpclient.a -l:libftplib.a -l:libdbclient.a -l:libsqlite3.a -l:libscheduler.a -l:libws2_32.a
SFTP_LDFLAGS= -static-libstdc++ -static-libgcc -s -L $(ROOT_DIR)/lib/Release -l:libboost_thread-mgw46-mt-1_49.a -l:libcommon.a \
-l:libfile.a -l:libfilesearcher.a -l:libdbclient.a -l:libsqlite3.a -l:libscheduler.a -l:libsftpclient.a -l:libws2_32.a -l:libssh.dll

Also I want to create debug/release build targets with own CXXFLAGS and output directories, so in result to get following:

TARGETS= ftp_auto_backup sftp_auto_backup

Screenshot of dirs tree here.

I want use implicit rule for compiling, smth like this:

%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $(O_DIR)/$@

But how can I specify separate O_DIR for each target int $(TARGETS) and for each build configuration? My main problem is in this step. I can paste all the makefile that I have at this moment, but it still won’t build anything. Just in case here it is: http://pastebin.com/jjB5Ld1s

Thanks in advance, guys!

  • 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-02T12:08:40+00:00Added an answer on June 2, 2026 at 12:08 pm

    There are many ways to do this. The simplest seems to be by means of recursive Make. (I am not among those who think that this is always a bad idea.)

    .PHONY: release
    release: VERSION=Release
    
    .PHONY: debug
    debug: VERSION=Debug
    
    release debug:
            @$(MAKE) -S ftp_auto_backup sftp_auto_backup VERSION=$(VERSION)
    

    Now to make the executables, given VERSION. We could handle the two project types with another layer of recursion, but we can do without it (and I won’t go into detail about preprocessor macros and compiler/linker flags, since you seem to know about them already– I’ll spell them out if you like):

    OBJ_LIST = foo.o bar.o baz.o
    
    ftp_auto_backup: PROJECT_TYPE=FTP
    ftp_auto_backup: $(addprefix $(VERSION)/ftp_auto_backup/obj/, $(OBJ_LIST))
    
    sftp_auto_backup: PROJECT_TYPE=SFTP
    sftp_auto_backup: $(addprefix $(VERSION)/sftp_auto_backup/obj/, $(OBJ_LIST))
    
    ftp_auto_backup sftp_auto_backup:
            @g++ -Wall $^ -o $@ with various flags
    
    $(VERSION)/ftp_auto_backup/obj/%.o: %.cc
            @g++ -Wall -c $< -o $@ with various flags
    
    $(VERSION)/sftp_auto_backup/obj/%.o: %.cc
            @g++ -Wall -c $< -o $@ with various flags
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your help. Say I have a code inside a for statement similar
need your help with GROUP BY clause. I have two tables: Managers and Clients
Need your help to get the max of CAP_PRICE based on certain criteria in
I need your help. I have a php script to send email to people
I need your help with this one again. I want to send special characters
Need your help with my PHP/MYSQL array. I have a php script that selects
need your help. I tried myself but cant solve it. I have a table
I need your help. I have been switching from various libraries trying to find
I need your help :) I have a EditText and below a ExpandableListView. I
I need your help in finding the appropriate code for getting the stored users

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.