I have a many c++ files in a folder:
> project
- a.cpp
- a.h
- b.cpp
- b.h
- main.cpp
- .editorconfig
- .gitignore
And use this command to compile my code:
g++ *.c* -o main
However I need organize my code in
> project
> src
> classes
- a.h
- b.h
> methods
- a.cpp
- b.cpp
- main.cpp
- .editorconfig
- .gitignore
Some questions:
1 – What command can I use to compile my project?
2 – Is it a good folder structure?
>Solution :
I would try to compile it with the following command:
g++ src/main.cpp src/methods/*.cpp -I src/classes -o myprogram
As long as your compilation times are reasonable, there is not much need to use a build system like Make yet.
I don’t know if it’s a good directory structure, but that’s a pretty subjective question. It’s more common to see directories named "include" or "header" than "classes", since it’s possible to have header files that do not define classes. I usually like to put all of the source files in the same directory unless there are a lot of them, or some are written by different teams.