I set set(CMAKE_SYSTEM_NAME Generic), then set CMAKE_C_FLAGS and CMAKE_EXE_LINKER_FLAGS,
I found that in addition to using the CMAKE_EXE_LINKER_FLAGS I set, the parameter CMAKE_C_FLAGS was also appended automatically when linking.
Is there any way to remove the CMAKE_C_FLAGS parameter from the link flags?
No. Some “compiler” flags have effects on the linker too (e.g., -pthread
or -fsanitize=
), so they are passed to both rules.
Why do you want to remove the flags?
I don’t think you’re getting it right. Things like -pthread only work at link time, it doesn’t work at compile time.
You’re thinking of -lpthread
. -pthread
also affects the compilation. Namely, it sets the _REENTRANT
and __USE_REENTRANT
symbols (which probably affect the standard libraries in various ways).