Hi,
I have prolly very noobish question. I compile my program separately with GCC by:

gcc -O2 -Wall -c foo.c

I just wat to ask if there is a chance to specify the output destination of foo.o file. Now the output is forwarded to the makefile dir.

Thank you for your interest.

Hi,
I just wat to ask if there is a chance to specify the output destination of foo.o file. Now the output is forwarded to the makefile dir.

I don't know of an option to specify the output directory for obj files, but you can specify a pathname for -o like gcc -c foo.c -o some/out/dir/foo.o However, you must also adjust your linking command to pick obj files from some/out/dir otherwise it'll try to recompile sources.

Hmm, so there is no way how to specify a pathname for

-c

. I'll make a workaround by moving the output by

mv

.

Edited 5 Years Ago by yuri1969: n/a

Hmm, so there is no way how to specify a pathname for -c. I'll make a workaround by moving the output by mv .

That's not the customary way to separate build dir from source dir. People generally cd to the build dir, and issue build commands from there.
e.g. say your sources are in my/project and you want object files in my/builddir , then you cd to my/builddir and compile like this: gcc -c ../project/foo.c Then object files are created in my/builddir.

That's not the customary way to separate build dir from source dir. People generally cd to the build dir, and issue build commands from there.
e.g. say your sources are in my/project and you want object files in my/builddir , then you cd to my/builddir and compile like this: gcc -c ../project/foo.c Then object files are created in my/builddir.

Ah, thank you for this hint!

This article has been dead for over six months. Start a new discussion instead.