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.

Sure try

gcc -O2 -Wall -c foo.c -o yourname.o

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

.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.