Author Topic: I would like to add src files to the proj without building ALL of them!  (Read 4961 times)

andycc57

  • Guest
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.

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: I would like to add src files to the proj without building ALL of them!
« Reply #1 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.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: I would like to add src files to the proj without building ALL of them!
« Reply #2 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 ?

ToApolytoXaos

  • Guest
Re: I would like to add src files to the proj without building ALL of them!
« Reply #3 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12193
    • Travis build status
Re: I would like to add src files to the proj without building ALL of them!
« Reply #4 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Krice

  • Almost regular
  • **
  • Posts: 130
Re: I would like to add src files to the proj without building ALL of them!
« Reply #5 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12193
    • Travis build status
Re: I would like to add src files to the proj without building ALL of them!
« Reply #6 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).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Krice

  • Almost regular
  • **
  • Posts: 130
Re: I would like to add src files to the proj without building ALL of them!
« Reply #7 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?

Online stahta01

  • Lives here!
  • ****
  • Posts: 6724
    • My Best Post
Re: I would like to add src files to the proj without building ALL of them!
« Reply #8 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.
 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12193
    • Travis build status
Re: I would like to add src files to the proj without building ALL of them!
« Reply #9 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: I would like to add src files to the proj without building ALL of them!
« Reply #10 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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Krice

  • Almost regular
  • **
  • Posts: 130
Re: I would like to add src files to the proj without building ALL of them!
« Reply #11 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12193
    • Travis build status
Re: I would like to add src files to the proj without building ALL of them!
« Reply #12 on: December 06, 2013, 03:53:46 pm »
Of course it will speed up the program, it is an optimizing compiler after all. :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]