How to compile a C code in one directory in another directory using GCC?

I want to compile a C source code which I wrote in one directory in another directory. Is it possible like this? If it is possible how do I achieve that?

1

1 Answer

Try this for compiling.

gcc file.c -o directory/myOutput

and run it.

./directory/myOutput 

if this doesn't work try this for compile and move the output file to a directory.

gcc file.c -o [compiled ouput file] & mv [compiled ouput file] [your directory]

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like