Monday, July 11, 2022

[SOLVED] How do I tell CMake to link the C standard library, not the C++ one?

Issue

I have a simple C++ file, but I do not want to use the C++ standard library, just the C one. Can this be done using CMake? Basically disabling access to the c++ headers, and only allowing linking to the C standard.


Solution

You can use target_compile_options(yourprog PRIVATE -nostdinc++) for clang and GCC based toolchains and /X with the path to its STL headers with msvc



Answered By - PeterT
Answer Checked By - Marilyn (WPSolving Volunteer)