Controlling location of object files

When I run the pgcc compiler it generates temporary object files in the working directory, regardless of where I output the end executable or object.

Is there a way to control where the temporary files generated during compilation go? I specifically want the intermediate object files to go into a sub-directory of my current working directory.

Hi Aaron,

For most compilers is done via the “-o” flag where you specify the path and file name. For example “-o objdir/foo.o”.

  • Mat

The -o option works fine to store the terminal object, that is, in my case, the module.so file, but there are .o files which are generated during the creation of the .so file which are not stored in the same directory as the .so file. How do I get those intermediate files generated during the creation of the final object to go to the same directory as the output file specified by -o?

The “-o” flag works for both compilation and linking. You just need to adjust the path to the appropriate directory where the object files are. Something like:

pgcc mysource.c -fpic -o objdir/mysource.o
pgcc objdir/mysource.o -shared -o libdir/libmylib.so

Your example uses a two phase compilation in which the first phase uses a .o object as the terminal object. As I mentioned above, I know that -o works for the terminal object, but it does not work for the intermediate objects, as shown in the example below adjusted from your example above:

pgcc -shared -fPIC -o libdir/libmylib.so mysource.c

Ok, my misunderstanding what you’re doing.

No, there’s no option to do what you want. You’ll need to move to the two-phase approach.

  • Mat