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

compilinggcc

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?

Best 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]
    
  • Related Question