Author Topic: multiple cpp files using codeblocks  (Read 16457 times)

computer_tech

  • Guest
multiple cpp files using codeblocks
« on: February 21, 2010, 11:25:57 pm »
Hello,

I have a newbie questions. For the life of me i cannot figure out a way to compile multiple files with codeblocks.

Can anyone give me a working example of HelloWorld using multiple cpp files.

Do i have to create a project to use multiple cpps?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: multiple cpp files using codeblocks
« Reply #1 on: February 22, 2010, 12:59:50 am »
Yes, you have...
(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 ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: multiple cpp files using codeblocks
« Reply #2 on: March 12, 2010, 02:05:34 pm »
Wouldn't this option allow for better compiler optimization, when used along with unit-at-atime?

I have made this manually as a post-build step, however this is way too inflexible for a multi-developer project.

Where is it placed on the to-do list, if at all? :) Maybe someone could give an estimate of how big this task would be? Doesn't seem like a complicated task at first thought, I have never looked into how the gcc compiler driver handles things internally though.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: multiple cpp files using codeblocks
« Reply #3 on: March 12, 2010, 02:17:42 pm »
WTF?  :shock:  :shock: I don't get anything from that you've said!
(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 ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: multiple cpp files using codeblocks
« Reply #4 on: March 12, 2010, 02:28:20 pm »
Right... hehehe

I was looking for the option to compile multiple files at once in order to have optimized release builds. Since this feature in not present in cb, i have considered i could go on and implement it myself (hopefully my c++ is better than my English?), but before that someone, who already has an overview of the project, could give an overview of what should and shouldn't be done to achieve that.

Offline Seronis

  • Almost regular
  • **
  • Posts: 197
Re: multiple cpp files using codeblocks
« Reply #5 on: March 12, 2010, 02:32:53 pm »
C::B supports multiple files just fine.  I have projects with between 6 and 600 files that C::B has never complained to me about.

you DID create a project first, didnt you?

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: multiple cpp files using codeblocks
« Reply #6 on: March 12, 2010, 02:41:20 pm »
OK. What i mean is have a nice built-in configuration support for

mingw32-g++.exe first.cpp second.cpp -o output.dll -shared   -Wl,--dll -s

versus what we get currently by default:

mingw32-g++.exe -c first.cpp -o first.o
mingw32-g++.exe -c second.cpp -o second.o
mingw32-g++.exe -shared   -Wl,--dll  first. o second.o   -o output.dll -s

Isn't it what this thread was all about from the start?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: multiple cpp files using codeblocks
« Reply #7 on: March 12, 2010, 02:46:54 pm »
OK. What i mean is have a nice built-in configuration support for

mingw32-g++.exe first.cpp second.cpp -o output.dll -shared   -Wl,--dll -s

versus what we get currently by default:

mingw32-g++.exe -c first.cpp -o first.o
mingw32-g++.exe -c second.cpp -o second.o
mingw32-g++.exe -shared   -Wl,--dll  first. o second.o   -o output.dll -s
Why do you think the former way of compiling is better?
The latter scales very well on a quad-, octa-, n-core machine. Can you say the same for the former?

Quote
Isn't it what this thread was all about from the start?
No it wasn't

Right... hehehe

I was looking for the option to compile multiple files at once in order to have optimized release builds. Since this feature in not present in cb....
C::B provides optimized builds when you use projects.... There is a release target that has -O2 switch by default.
(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 ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: multiple cpp files using codeblocks
« Reply #8 on: March 12, 2010, 03:01:48 pm »
Then I really misunderstood the point of the original question. I am able to create projects in codeblocks and to compile just fine with compiler switches of my choice. This is not an issue.

Quote
The latter scales very well on a quad-, octa-, n-core machine. Can you say the same for the former?
I haven't noticed that separate translation units would be compiled in parallel on my dual-core machine, at least not visually The output window does not indicated that in any way.

Anyways. That was not my concern. Say, take a look here http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Optimize-Options.html

Quote
Using the -funit-at-a-time flag will allow the compiler to consider information gained from later functions in the file when compiling a function. Compiling multiple files at once to a single output file (and using -funit-at-a-time) will allow the compiler to use information gained from all of the files when compiling each of them.

I believe that holds true if source code is compiled the way i have shown. Of course one has to compile with -funit-at-a-time optimization switch included.

This is a very valid feature for an ide like cb is, not?
« Last Edit: March 12, 2010, 03:15:01 pm by ewww »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: multiple cpp files using codeblocks
« Reply #9 on: March 12, 2010, 03:16:48 pm »
I haven't noticed that separate translation units would be compiled in parallel on my dual-core machine, at least not visually The output window does not indicated that in any way.
There is an option for the number of processes to use in Settings -> Compiler and Debugger -> Compiler -> Other (I think)

Quote
Using the -funit-at-a-time flag will allow the compiler to consider information gained from later functions in the file when compiling a function. Compiling multiple files at once to a single output file (and using -funit-at-a-time) will allow the compiler to use information gained from all of the files when compiling each of them.

I believe that holds true if source code is compiled the way i have shown. Of course one has to include something like -O2 or -funit-at-a-time to have any benefit from it.

This is a very valid feature for an ide like cb is, not?
Can you prove that there is a gain? You can test two executables build using the two schemes and measure the difference in execution speed?

BTW, There is a chance that you'll get better speed/performance if you upgrade your compiler :)
p.s. also look at Link Time Object generation, or something like that in gcc 4.5
(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 ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: multiple cpp files using codeblocks
« Reply #10 on: March 12, 2010, 03:33:43 pm »
Quote
Can you prove that there is a gain? You can test two executables build using the two schemes and measure the difference in execution speed?

BTW, There is a chance that you'll get better speed/performance if you upgrade your compiler :)
p.s. also look at Link Time Object generation, or something like that in gcc 4.5

Yes, that is something of similar functionality like link time object generation. However I am not that lucky to have a freedom of changing compilers at will. There are such nasty things like build servers and then other engineers somewhere around the world, who are, so to say, not really into software development, but still need to be able to compile the source code. You should get the picture :) We did update to 4.4.0 in the beginning of it all however.

I do not have the proof for you. Is adding this functionality worth the effort? That was a part of my question - a codeblocks developer could quickly outline, how much effort there is to have that implemented.

For instance, SQLite is distributing it's source code primarily as an amalgamation - all code put into a single translation unit. They claim a 5%-10% performance gain from that alone. A db engine is quite a special case, I agree. Most of user applications would probably gain much less from it. Still, it is a feature supported by gcc and I guess all of the advanced optimizing compilers, so it would be good to have an option to quickly switch to this kind of configuration for making release builds.
« Last Edit: March 12, 2010, 03:35:18 pm by ewww »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: multiple cpp files using codeblocks
« Reply #11 on: March 12, 2010, 04:13:05 pm »
@ewww

Why not use an Makefie?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: multiple cpp files using codeblocks
« Reply #12 on: March 12, 2010, 04:14:52 pm »
Quote
Can you prove that there is a gain? You can test two executables build using the two schemes and measure the difference in execution speed?

BTW, There is a chance that you'll get better speed/performance if you upgrade your compiler :)
p.s. also look at Link Time Object generation, or something like that in gcc 4.5

Yes, that is something of similar functionality like link time object generation. However I am not that lucky to have a freedom of changing compilers at will. There are such nasty things like build servers and then other engineers somewhere around the world, who are, so to say, not really into software development, but still need to be able to compile the source code. You should get the picture :) We did update to 4.4.0 in the beginning of it all however.

I do not have the proof for you. Is adding this functionality worth the effort? That was a part of my question - a codeblocks developer could quickly outline, how much effort there is to have that implemented.

For instance, SQLite is distributing it's source code primarily as an amalgamation - all code put into a single translation unit. They claim a 5%-10% performance gain from that alone. A db engine is quite a special case, I agree. Most of user applications would probably gain much less from it. Still, it is a feature supported by gcc and I guess all of the advanced optimizing compilers, so it would be good to have an option to quickly switch to this kind of configuration for making release builds.

It is NOT possible to do it. There is a limit to how long a command line can be.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: multiple cpp files using codeblocks
« Reply #13 on: March 12, 2010, 04:21:13 pm »
For instance, SQLite is distributing it's source code primarily as an amalgamation - all code put into a single translation unit. They claim a 5%-10% performance gain from that alone. A db engine is quite a special case, I agree. Most of user applications would probably gain much less from it. Still, it is a feature supported by gcc and I guess all of the advanced optimizing compilers, so it would be good to have an option to quickly switch to this kind of configuration for making release builds.

You can do that very easy


Code
// in main.cpp
// the only file that is added for compilation
// add

#include "file1.cpp"
#include "file2.cpp"
#include "file3.cpp"
.
.
.
#include "file_n.cpp"

(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!]