Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: andycc57 on November 29, 2013, 03:31:28 am

Title: I would like to add src files to the proj without building ALL of them!
Post by: andycc57 on November 29, 2013, 03:31:28 am
I'm on Linux with C::B version 10.05.

After adding any file, the "compile file" and "link file" flags are set to true (ticked). Only my main.cpp should get built - it has #include statements that pull in all other files recursively. All library include lines (such as "#include <vector>" and "#include <iostream>") are at the top of main.cpp and nowhere else - the compiler fails due to this, since it wrongly tries to build bus.cpp first (alphabetical). Vector is not defined, cout is not defined, etc. The compiler only needs to build main.cpp.

In the project file manager I can right click on each individual file, select properties, go to the Build tab, uncheck "compile file" and "link file". That works. I have some projects though with up to 100 source files - that is going to take too long.

How can I change which files get built? When adding, the only option is telling C::B which targets the file should belong to. If I select no targets, it just asks again until I pick one or more. Surely I'm missing something here.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: ouch on November 29, 2013, 06:29:53 am
Upgrade to the newer version of codeblocks... 10.05 is a very, very, old version of codeblocks... I would recommend a nightly build myself.

But you can find a priority weight slider in the new versions in that same build menu. This allows you to specify the build order of individual files.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: Jenna on November 29, 2013, 06:32:55 am
I'm not sure if I understand correctly:
Do you include the other cpp-files in main.cpp with the #include-statement ?
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: ToApolytoXaos on November 29, 2013, 08:00:14 am
I'm on Linux with C::B version 10.05.

After adding any file, the "compile file" and "link file" flags are set to true (ticked). Only my main.cpp should get built - it has #include statements that pull in all other files recursively. All library include lines (such as "#include <vector>" and "#include <iostream>") are at the top of main.cpp and nowhere else - the compiler fails due to this, since it wrongly tries to build bus.cpp first (alphabetical). Vector is not defined, cout is not defined, etc. The compiler only needs to build main.cpp.

In the project file manager I can right click on each individual file, select properties, go to the Build tab, uncheck "compile file" and "link file". That works. I have some projects though with up to 100 source files - that is going to take too long.

How can I change which files get built? When adding, the only option is telling C::B which targets the file should belong to. If I select no targets, it just asks again until I pick one or more. Surely I'm missing something here.

If I understood correctly, you have a project which includes 100 files more or less, but you want to build one file at a time so you may see the actual output of each file? Am I correct?

If that is the case, well I don't know of any different way other than remove the files from project, (which does not delete them from project directory, just to let you know to have no worries) and include each file one-by-one and compile it upon request.

Now, about your building issue with header files, I would suggest to follow the well-known concept Declaration / Implementation / Use; that is, in your Declaration [header] file(s), declare your structures / classes, function prototypes, and include the necessary header files which implementation files will going to use. Then, in your implementation file call your own header file that includes the aforementioned information, and in your use file, that is your main.cpp, you may include your header file to generate the desire linkage so it can produce the executable.

I hope it make sense to you.

Cheers.

P.S.: If you need me to produce a tiny demo for you, please by all means, do not hesitate to ask me so I can gladly create it for you.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: oBFusCATed on November 29, 2013, 10:35:30 am
You can write a script to disable them all at once.
See here: http://wiki.codeblocks.org/index.php?title=Scripting_commands#ProjectFile
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: Krice on November 30, 2013, 11:28:28 am
How can I change which files get built?

By not including everything in main.cpp. Instead use correct C++ programming, including header files in cpp files that need them. That way C::B will compile only changed files.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: oBFusCATed on November 30, 2013, 11:52:43 am
By not including everything in main.cpp. Instead use correct C++ programming, including header files in cpp files that need them. That way C::B will compile only changed files.
Your comment is not constructive!
The OP might have his reasons to do what he is trying to do.

For example I know that SQLite people has a mode for building in this way and they gain some performance from it
(because the compiler can see all the function and do its magic).
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: Krice on November 30, 2013, 10:34:44 pm
For example I know that SQLite people has a mode for building in this way and they gain some performance from it (because the compiler can see all the function and do its magic).

Please explain more about this magic. How doesn't compiler "see" all functions in any cases?
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: stahta01 on November 30, 2013, 10:43:21 pm
For example I know that SQLite people has a mode for building in this way and they gain some performance from it (because the compiler can see all the function and do its magic).

Please explain more about this magic. How doesn't compiler "see" all functions in any cases?

Likely code optimization is made easier by seeing all the code at once.
But, the main reason I think SQLite uses a single effective c/c++ file is ease of use is improved for some cases.

Tim S.
 
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: oBFusCATed on December 01, 2013, 12:15:50 am
Please explain more about this magic. How doesn't compiler "see" all functions in any cases?
The compiler can optimize better, because it sees all functions and code, so it can do better inlining, const propagation, etc. You get the same benefits like with the newer -flto flag.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: thomas on December 01, 2013, 01:18:42 pm
Not sure if I understand this correctly, but when you add an entire hierarchy of files, you're being asked what targets, if any, to add the files to (I've not done this for a long time, but used to be like that).

If you don't want them compiled, just don't add them to a target.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: Krice on December 06, 2013, 02:38:02 pm
The compiler can optimize better, because it sees all functions and code, so it can do better inlining, const propagation, etc.

But how the compiler can optimize anything if there are more than one module? I know from my experience that GCC's -O2 does speed up the program even I'm using one header+cpp file per class -style.
Title: Re: I would like to add src files to the proj without building ALL of them!
Post by: oBFusCATed on December 06, 2013, 03:53:46 pm
Of course it will speed up the program, it is an optimizing compiler after all. :)