My Problem
I read somewhere that to add include paths to g++ you need to use the -I
option:
g++ -I /some/directory and_then_my_files.cpp
However, I'm not sure if this is actually what I need. It's currently not working for me, and I couldn't find anything else close to what I have.
My Setup
I've got a directory with all my current project code, and in it a subdirectory classes
, that contains various .h
and .cpp
files containing classes that may or may not be used when compiling my main files.
Since g++ ./classes/*.cpp main.cpp
takes a long time (large number of files in classes
directory), I'm looking for an alternative that only compiles and links the files that are included in the main file.
Main file:
#include "classes/a.h"
#include "classes/b.h"
// ... my code
And as you can imagine, g++ complains about undefined references to classes A and B, unless I add ./classes/*.cpp
to the build command.
What I want to achieve
So -I
and -L
did not work, and adding the whole directory to the build command results in a ridiculously long build time - I'm talking 3-5 minutes, which really slows down my development speed.
Is there any way to only build/link the included classes from my classes
directory, such as only classes A and B from the example I gave above?
Small Recap of what I've already tried
g++ -I ./classes main.cpp -o main
g++ -L ./classes main.cpp -o main
(probably stupid but I tried it anyway)
g++ ./classes/*.cpp main.cpp -o main
(what I currently have to resort to)
Thanks in advance :)