name of object compiled by current translation unit in C
is there a macro or a global variable which through which I can learn about the n开发者_开发技巧ame of the object file the current translation unit will be used for in C? I am only aware of the source file macro.
Thanks.
Not in standard C.
The preprocessor may be implemented as a separate program that has no knowledge of object files, so it can't be a built-in macro.
A compiler could in theory produce a symbol with the object file name, but that would be invalidated as soon as the object file is renamed by the user.
You can get the build system to #define
the object name:
# Compile ${module}.c to ${module}.o
cc ${CPPFLAGS} ${CFLAGS} -DOBJNAME=${module}.o -c -o ${module.o} ${module}.c
but the point about renaming still stands.
(This is just a snippet of shell code, but it could be turned into a Makefile
rule, I suppose.)
I don't think this exists. The only thing I can come up with is you could use the ## glue macro to combine __FILE__
with ".o"... But even that isn't exactly what your asking for as you'd get foo.c.o.
精彩评论