Is there a macro that I can #ifdef
for to check if librt has been linked to, ie by -lrt
with gcc?
Asked
Active
Viewed 1,806 times
0

hippietrail
- 15,848
- 18
- 99
- 158

chew socks
- 1,406
- 2
- 17
- 37
-
1Could you explain why you need that? (The pre-processor generally doesn't have a clue about linker stuff, it runs way before linking is even considered.) – Mat Feb 25 '13 at 06:20
-
I was putting together a folder of functions I commonly use and don't want to have to keep writing. One of the functions in the timing file depends on `librt` and so causes compilation to fail if that file is included without linking to `librt` even if that function is not called. – chew socks Feb 25 '13 at 07:21
-
1That's something you need to deal with in your build system, not in the source code. If someone just compiles (and doesn't link yet) that file, there will be no linker flags at all and that wouldn't be a problem. – Mat Feb 25 '13 at 07:36
-
I see. I don't actually have a "build system". I've just created a bash alias for g++ to include a directory of my header files in the `#include` search. – chew socks Feb 25 '13 at 07:42
-
1@chewsocks, then your `.bash_profile` *is* your build system ;-). – binki Mar 29 '15 at 00:05
-
1@chewsocks, so in your buildsystem, just replace `-lrt` with `-DI_WANT_LIBRT -lrt` and there you go. – binki Mar 29 '15 at 00:06
1 Answers
1
No, gcc doesn't have such macro (I've dumped preprocessor macros to check). On Windows with Microsoft compiler you can use _VC_NODEFAULTLIB
macro to detect builds without libc
reference.

Marat Dukhan
- 11,993
- 4
- 27
- 41
-
Thank you for checking. Can you show how you dumped the preprocessor macros so I (and others) can do it in the future? – chew socks Feb 25 '13 at 07:22