Author Topic: Copying object files from one folder to another one during compiling process  (Read 8766 times)

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 39
My project has the following folderds:
<main_dir>\project.cbp
<main_dir>\src\main.c
<main_dir>\src\f1\f1.c
<main_dir>\src\f2\f2.c

For a strange reason (if you're curious I can tell you about) I need to store all object files in <main_dir>\OBJ folder, before linking. In other words, after compiling process the object files should be located in:
<main_dir>\obj\main.obj
<main_dir>\obj\f1.obj
<main_dir>\obj\f2.obj

Unfortunately, if I set <main_dir\obj folder as the output object folder in the project configuration settings, I have:
<main_dir>\obj\main.obj
<main_dir>\obj\f1\f1.obj
<main_dir>\obj\f2\f2.obj

I was thinking to copy object files from one folder to another one with post-build steps, but I think it's not possible to execute a command after each file compilation, only after linking process.

Another solution could be to change the compiler command from
  $compiler $options $includes -o $object -c $file
to
  $compiler $options $includes -o $objects_output_dir/$file_name.obj -c $file
But in this way the make process doesn't work. CodeBlocks compiles source files every time, even if they aren't changed since the last compilation time, because it couldn't find the object file where he supposed to be.

Any suggestions?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Any suggestions?

Try "Settings -> Compiler and debugger... -> [the compiler you use] -> Other settings -> Advanced options... -> Others -> Use flat objects:"
"Other settings might be hidden (it's the right-most tab) and after you clicked "Advanced options" you have to answer with "Yes".

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 39
Try "Settings -> Compiler and debugger... -> [the compiler you use] -> Other settings -> Advanced options... -> Others -> Use flat objects:"
Good! It worked for me as I want.  :D

There's just a small strange behaviour. After compilation, I'll have many empty folders under OBJ directory:
  <main_dir>\obj\f1
  <main_dir>\obj\f2
but the object files are all in <main_dir>\obj.
If I delete the obj folder (with all the sub-folders), after compilation I have again the directory structure.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
I noticed it too.
I never used flat objects before.
I will look into it.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
the flat objects work (I added that feature), those dirs are still created, I think they are created earlier in the build process. I didn't look into it any furhter back in the days, since i got the object files where I wanted them to show up, all next one another, nicely flat ;-)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Fixed in svn r6874.