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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:38:19+00:00 2026-06-15T09:38:19+00:00

I am trying to setup a build process using makefiles, for a C++ plugin

  • 0

I am trying to setup a build process using makefiles, for a C++ plugin that I am working on. I am curious to know if there is any way to make g++ compile source files found in another directory. My motivation for doing this is to avoid having to specify the relative path for each source file, as I explain below.

My project directory structure looks like:

MyPlugin --> src   --> Foo.cpp
                   --> Foo.h
                   --> Bar.cpp
                   --> Bar.cpp
         --> build --> Makefile

Following is a stripped down version of my current Makefile:

SRC_PATH=../src
OUT_PATH=../bin
VPATH=${SRC_PATH}
FILES=Foo.cpp Bar.cpp

CC=g++
CFLAGS=-Wall -shared

all:
    mkdir -p ${OUT_PATH}
    ${CC} ${CFLAGS} -I${SRC_PATH} ${FILES} -o ${OUT_PATH}/MyPlugin.so

By doing this, I am trying to avoid defining the FILES variable as below:

FILES=../src/Foo.cpp ../src/Bar.cpp

When I tried running make all, g++ gave me an error. It looks like the path specified through -I flag is only used to search for #included files.

g++: Foo.cpp: No such file or directory
g++: Bar.cpp: No such file or directory

I cannot use wildcards (*.cpp) because I do not always want all the files to be picked up for compilation. Another alternative is to cd to the src directory, as mentioned here, and run g++ from there, but that only works for me if all the files are in the same directory (I need the output to be a single .so file). I also tried setting the environment variable PATH, but that didn’t seem to have any effect.

I have looked into the g++ help, the make documentation, and looked at StackOverflow posts such as https://stackoverflow.com/questions/10010741/g-compile-with-codes-of-base-class-in-a-separate-directory and gcc/g++: "No such file or directory" , but could not find any solution which I could use. Could you please suggest me an suitable approach to this problem?

Edit The example may have been misleading. In this stripped down example, I have all the source files in one directory, but in my actual project, I have several subdirectories, and multiple files in each directory. Thus, although cding to the src directory works in my above example, it won’t work in my actual project (or at least, I would like to know how it would work).

  • 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-15T09:38:19+00:00Added an answer on June 15, 2026 at 9:38 am

    You can have second variable for the actual source files, like this:

    FILES = Foo.cpp Bar.cpp
    SOURCES = $(FILES:%.cpp=$(SRC_PATH)/%.cpp)
    

    Then instead of using FILES when building you use SOURCES.

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

Sidebar

Related Questions

I'm trying to setup a build file and I was curious if you can
I'm trying to debug an MS-Build in VS2010 setup that reports about a half-dozen
I'm trying to improve our build process, and to that end I've been looking
I'm trying to build a process that will repopulate an item that was inserted
I am trying to get a build process set up in TeamCity 5, and
I am trying to setup build enviroment for android on my ubunt10.04 machine. For
I am trying to setup a TFS Build, and am having trouble getting my
I am trying to setup an automated build of my Windows CE application. However,
I'm trying to setup a continuous integration build on TFS 2008. In the project
I am trying to setup a shared authentication system on a build server. We

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.