Switched to Visual Studio Code in an effort to understand C/C++ dev tools and to stop relying on IDEs. I try to use Makefiles for this purpose because it allows to run compilation via command line on a target device (no GUI == no IDE). So far I've managed to make a generic Makefile that compiles all .cpp
files to corresponding .o
files and then links it all together. It works for small projects that store all sources in a single directory. Now I must port my working Xcode project.
The problem is that the source files are stored in a directory tree (no single directory) and may be both C
and C++
. Some files have similar filenames but reside in different folder. From C++ perspective it means classes the have same name, but different namespaces. Various IDEs handle this easily but Makefile gives me all sorts of problems cause I am not yet a make guru.
I've tried to create Makefiles in each directory (I failed), but then I read that is considered a bad approach so I switched to a single Makefile approach. Some say I should switch to CMake but I think that it is pointless without understanding the Makefile creation first because CMake would eventually create one. It would also allow to build and install on devices without CMake and other cool tools (if, for example, there is no Internet connection to download CMake).
Here is a basic idea:
- project-name/
- application/
- core/
- loader.hpp
- loader.cpp
- ...
- loader.hpp
- loader.cpp
- ...
- hardware/
- loader.hpp
- loader.cpp
- ...
- some-c-library
- library.h
- library.c
- ...
- main.cpp
- project-name.xcodeproj
- Makefile
TR&DL: Unable to make complicated Makefile. GNU manual is hard to understand and online blogs/tutorials mostly touch only basic stuff.