Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: bart again (UCX64) Date: Fri, 01 Sep 2023 14:31:58 -0700 Organization: None to speak of Lines: 54 Message-ID: <87msy57f75.fsf@nosuchdomain.example.com> References: <20230828174502.a279eb2b4ea06fac68dc6561@g{oogle}mail.com> <65d28a7d-ffd5-4b8b-b3f0-2500bb05f9b7n@googlegroups.com> <557bf807-40c7-404b-9242-c26975faa42fn@googlegroups.com> <20230901102320.265@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="3d717a41e44a951774a492dc9105dbfa"; logging-data="37676"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pASXRmNK1fvcsuDY3gFPA" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:kUt4boAQ1eLBw1odigs5G1arqBw= sha1:8U9nx6rUC1M23oatj32iu1Y+OUo= Xref: csiph.com comp.lang.c:173584 Kaz Kylheku <864-117-4973@kylheku.com> writes: > On 2023-09-01, Bart wrote: >> On 01/09/2023 09:43, David Brown wrote: >>> On 31/08/2023 21:26, Bart wrote: >> >>> Putting object files in the current directory is a useful default. >> >> 'gcc -c' will do that if the input file is in the same current directory. >> >> So if the current directory happens to be /abc, compiling hello.c will >> produce /abc/hello.o from /abc/hello.c. > > You are right. I didn't even notice that or forgot about it all these > years. -c is only used in very trivial makefiles. > > The built-in make recipe doesn't use it; it uses -o so that if you say, > > obj/foo.o: src/foo.c > > it works fine. > According to the gcc man page, I would think that > -c turns src/foo.c into src/foo.o. Yes, and it works by invoking gcc with the "-c" option, which make knows how to do. For GNU make, `make -p` dumps the data base of rules and variable values. On my system, part of the output is: COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c Ignoring directory issues, if you want to generate an object file foo.o from a C source file foo.c, you can use `gcc foo.c -c` or `gcc -c foo.c` -- or, if you want to be explicit, `gcc foo.c -c -o foo.o`. If you do `gcc foo.c -o foo.o`, the lack of a `-c` option tells it to invoke the linker. It will create an executable, not an object file, named "foo.o". That's very probably not what you want. > Quote > > By default, the object file name for a source file is made by > replacing the suffix .c, .i, .s, etc., with .o. I agree that's potentially misleading. I think the intent was that "object file name" is intended to refer just to the file *name*, not the full file *path*. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */