r/cpp_questions • u/Dawn232023 • 21d ago
OPEN Any sources to learn how C++ source projects get lowered from source code to intermediate representation and eventually to code gen part.
Can someone help me out....I'm not able to find any proper sources to follow how c++ projects get lowered from sources codes with headers and archive files to intermediate representation and then object files and shared files and linking like how do they work and their internals ....just trying to learn about them.
1
u/Discordbothost 20d ago
LLD's ELF archive docs cover that linker question: https://lld.llvm.org/ELF/warn_backrefs.html
try a tiny object + static archive example with GNU ld and LLD. they can resolve the same archive ordering differently, which is hard to spot in a large CMake build.
1
u/HeeTrouse51847 21d ago
the point of cmake is to have a higher level build tool so you DONT have to deal with platform or compiler specific stuff. In a perfect world, your entire C++ project is completely defined by your source files and your CMakeLists.txt and solely based on those can be built on any platform by just running
cmake -B build
cmake --build build
In reality, you still often need to pass specific compiler options or handle OS specific cases separately. Adding Third party libraries to your project also isnt something that has a single "best solution". You can install them manually and make CMake find them. Or you can use "fetch content" (a cmake mechanism to pull git repos of 3rd party libs) or use a package manager like vcpkg or conan and connect them into your cmake project. (I recommend conan)
I would recommend starting to learn how to setup your C++ projects with CMake and then have a look at how to use the Conan package manager.
You mentioned you want to use the LLVM test suite, may I ask, why?
I have never used it before or heard of it, but quickly glancing over it, my understanding is this:
It's not a regular C++ library, it's a project to test your local LLVM installation. To me, it does not seem trivial.
If you are a beginner and just want a unit test library, use Google Test or Catch2 instead.
0
u/davidc538 20d ago
If you know some assembly, Crafting Interpreters is a good book that helps bridge the gap.
4
u/trichotomy00 21d ago
are you asking how compilers work?