0

I tried to compile .c file to .o and it is located in specific directory. The similar question is here but this is not what I'm looking for.

For some reason, I don't want to use -o option now. I'm using -c option. The default output path of gcc -c is current directory. I tried to redirect it into some specific directory such as /objs. How can I achieve it?

Steven
  • 811
  • 4
  • 23
  • `For some reason, I don't want to use -o option now` Sooo for what reason? `The similar question is here but this is not what I'm looking for.` Why isn't it? Doesn't ex. https://stackoverflow.com/a/1814344/9072753 answer it? `I tried to redirect it into some specific directory` What and how have you tried it exactly? – KamilCuk Jul 13 '21 at 15:31
  • I will use link script to link all of the object files later – Steven Jul 13 '21 at 15:34
  • How does using a link script _later_ to link all object files prevent you from using `-o` option? – KamilCuk Jul 13 '21 at 15:35
  • To use linker script is the second stage in my case and it will use -o option. Now my question is in first stage, try to use -c option to generate object files in specific directory – Steven Jul 13 '21 at 15:38
  • Great - so use `-o` option with gcc to specify output file location. Or use ex. https://stackoverflow.com/a/1814344/9072753 answer. (But overall, move to cmake, bazel, scons or other build systems that were made specifically to figure such stuff for you). I do not understand - I still fail to see what does prevent you from using `-o` option. – KamilCuk Jul 13 '21 at 15:39
  • But I don't want to link all needed functions at first (`-o`) – Steven Jul 13 '21 at 15:46
  • 1
    If you use `-c` no linking is done at all, and in that case adding `-o` does nothing more than specify where the output object file should go. To be clear, what's being suggested is `gcc -c -o /objs/foo.o foo.c`. – Nate Eldredge Jul 13 '21 at 15:48
  • 1
    It seems like maybe you have some confusion over what `-o` actually does. – Nate Eldredge Jul 13 '21 at 15:53
  • yes, ur right. I has some confusion about it. – Steven Jul 13 '21 at 15:55

0 Answers0