Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How compile a c++ complex folder with a simple command?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

> 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading