Author Topic: Put all the .o files in an "obj" subdirectory  (Read 7046 times)

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 16
Put all the .o files in an "obj" subdirectory
« on: July 02, 2012, 10:10:16 am »
   It seems there is problem that the paremters of g++ contains too many characters and the linker stopped the creation of the DLL.

My question is:

   for example, I have a directory structure like this:

src
- Foo.cpp
- Bar.cpp
test
- FooTest.cpp
- BarTest.cpp
- Main.cpp

By using Code::blocks, is there a way
putting all the .o files in an "obj" subdirectory of the "test" directory?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Put all the .o files in an "obj" subdirectory
« Reply #1 on: July 02, 2012, 10:57:04 am »
putting all the .o files in an "obj" subdirectory of the "test" directory?
Yes, just setup the object output folder accordingly in your project settings.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Put all the .o files in an "obj" subdirectory
« Reply #2 on: July 02, 2012, 11:54:14 am »
putting all the .o files in an "obj" subdirectory of the "test" directory?
Yes, just setup the object output folder accordingly in your project settings.
Thanks your replay, while I had a try for several times, it seem no any changes, currently, I set objects output dir: test, it always create a main.o file and put it into test directory, and foo.o and bar.o into src directory. my intention is all objects  file is put in test directory and there are no any subdirectory in test directory. how to setup, or could you give an example?

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Put all the .o files in an "obj" subdirectory
« Reply #3 on: July 11, 2012, 12:29:38 pm »
putting all the .o files in an "obj" subdirectory of the "test" directory?
Yes, just setup the object output folder accordingly in your project settings.
Thanks your replay, while I had a try for several times, it seem no any changes, currently, I set objects output dir: test, it always create a main.o file and put it into test directory, and foo.o and bar.o into src directory. my intention is all objects  file is put in test directory and there are no any subdirectory in test directory. how to setup, or could you give an example?

Can anybody help me?

Offline cacb

  • Lives here!
  • ****
  • Posts: 547
Re: Put all the .o files in an "obj" subdirectory
« Reply #4 on: July 11, 2012, 02:16:55 pm »
Can anybody help me?

See attached.

Select the project in C::B, riight-click and choose "Properties ...", then select the Build targets tab. You can then set the output dir for each target to anything you want. I chose to collect all under a "hidden" .cmp folder, and then have subdirs for different compilers (some of my projects can use different compilers on the same platform).

it is also possible to edit the .cbp project file for things like this (if you know what you are doing), here is a snippet
Code
                 ...
<Build>
<Target title="MSVC_Debug">
<Option output=".cmp\msvc\bin\Debug\cf_xmld" prefix_auto="1" extension_auto="1" />
<Option object_output=".cmp\msvc\obj\Debug\" />
<Option type="3" />
<Option compiler="msvc" />
                                ...

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Put all the .o files in an "obj" subdirectory
« Reply #5 on: July 12, 2012, 12:06:49 pm »
Can anybody help me?

See attached.

Select the project in C::B, riight-click and choose "Properties ...", then select the Build targets tab. You can then set the output dir for each target to anything you want. I chose to collect all under a "hidden" .cmp folder, and then have subdirs for different compilers (some of my projects can use different compilers on the same platform).

it is also possible to edit the .cbp project file for things like this (if you know what you are doing), here is a snippet
Code
                 ...
<Build>
<Target title="MSVC_Debug">
<Option output=".cmp\msvc\bin\Debug\cf_xmld" prefix_auto="1" extension_auto="1" />
<Option object_output=".cmp\msvc\obj\Debug\" />
<Option type="3" />
<Option compiler="msvc" />
                               ...
Thanks a lot, maybe I didn't make it clear, my intention is:
for example, in a project, there are more than one files in two directory, the directory  structure of the project  is as follows:

    
                                |-----main( directory which has files main.cpp and main.h)
                                |
                                |
 project( directory)---  |-----test( directory which has files test.h and test.cpp)
                                |
                                |
                                |------debug( directory for object files)

 Currently, after being built, the object files in debug directory are as follows,

                            |-----test (directroy which has object file- test.o)
                            |
debug (directroy)--- |
                            |--main.o
                                                                                


                                                                                                     |---main.o
my intention is all object files in debug directory like this( debug directory--|                   ) and no subdirectory test is created.
                                                                                                     |---test.o,


BTW, I currently built a large dll with a lot of cpp files and it seems
the paremters of g++ contains too many characters and the linker stopped the creation of the DLL.

so if anybody can give me another solution to solve the problem, I'm also appreciated.
« Last Edit: July 12, 2012, 12:35:12 pm by jank9201 »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Put all the .o files in an "obj" subdirectory
« Reply #6 on: July 12, 2012, 12:31:25 pm »
Check "Settings -> Compiler [and debugger] -> Global compiler options -> the_compiler_you_use -> Other settings -> Advanced options -> Others -> Use Flat objects".

But this setting is used for all projects, that use this compiler.
... and for larger projects, which might have source files with the same name in different subdirectories, the setting breaks your build.
Be warned !

Offline jank9201

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Put all the .o files in an "obj" subdirectory
« Reply #7 on: July 13, 2012, 02:31:42 am »
Check "Settings -> Compiler [and debugger] -> Global compiler options -> the_compiler_you_use -> Other settings -> Advanced options -> Others -> Use Flat objects".

But this setting is used for all projects, that use this compiler.
... and for larger projects, which might have source files with the same name in different subdirectories, the setting breaks your build.
Be warned !

Great!!!, I test it with a small project, it does works, thanks a lot!
I'll test it with my dll project, again, thank you very much!!!