Author Topic: How do I set include directories per "sub-project" ?  (Read 3755 times)

Offline ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
How do I set include directories per "sub-project" ?
« on: June 13, 2016, 03:01:23 pm »
I have a Makefile for a large project that builds with make and mingw, but I would like to build it with Code::Blocks, so I need to create a C::B project.

I built the project in MinGW console and did a make -k to see everything that went on. Then I grepped every gcc and g++ line to get a list of all files that were being built, and what -I directives they were using.

The project consists of a number of "sub-projects" that have their own include directories supplied to make with -I.

How can I do the same in C::B? That is, set up sub-projects, without only linking to pre-generated .o files, because I want to be able to debug all the sources with stepping.

So far I tried adding all the .c and .cpp files to the .cbp file, and adding all the include directories (<Add directory=...) under the <Compiler> tag.

I can get the project to start building, but I immediately run into errors which I believe are caused by including all the directories at once on the project level, instead of individually per "sub-project". The project probably also needs different compiler directives per "sub-project".

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7091
    • My Best Post
Re: How do I set include directories per "sub-project" ?
« Reply #1 on: June 13, 2016, 03:27:00 pm »
So far I tried adding all the .c and .cpp files to the .cbp file, and adding all the include directories (<Add directory=...) under the <Compiler> tag.

That was the wrong choice!!

Create an CB Project target for each separate sub-make  command.
Then, add the files and options to the target.

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 ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #2 on: June 13, 2016, 05:47:17 pm »
Create an CB Project target for each separate sub-make  command.
Then, add the files and options to the target.
I'm not sure I understand. Should I create a number of C::B Projects, each containing the files that were compiled into a particular .o ?

When I have done that, how do I make a project out of those projects?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7091
    • My Best Post
Re: How do I set include directories per "sub-project" ?
« Reply #3 on: June 13, 2016, 06:12:18 pm »
Read this FAQ.

http://wiki.codeblocks.org/index.php/FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

NOTE: Read the above FAQ before answering!

Do you know what the difference between Global Compiler setting, CB Project setting, and CB Target setting is?

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 ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #4 on: June 13, 2016, 08:07:23 pm »
Do you know what the difference between Global Compiler setting, CB Project setting, and CB Target setting is?
Yes of course.

I don't think the FAQ addresses my problems.

My problem is that if I just add the object files as libraries and point to the .h files, then when I start the debugger, I just get a lot of "unknown" sources that will not show up in code follow (so I can not see the source code of the machine instructions that are being stepped over, because C::B thinks the machine code comes from an unknown source).

So, I would like to make a project that in one way or another includes all the source files, so that C::B debugger will understand what machine code corresponds to what source line in which file.
« Last Edit: June 13, 2016, 08:09:42 pm by ta0 »

Offline ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #5 on: June 13, 2016, 08:12:56 pm »
That was the wrong choice!!

From your later response I think you misunderstood me.

In my project .cbp file, there is the following XML hierarchy:
<Project>
    <Build>
        <Target title="Debug">
            <Compiler>
                <Add directory="c:\myproject\include" />

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7091
    • My Best Post
Re: How do I set include directories per "sub-project" ?
« Reply #6 on: June 13, 2016, 09:10:30 pm »
Hand editing of the CB File is NOT even recommended for experts!

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 ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #7 on: June 13, 2016, 09:16:44 pm »
Hand editing of the CB File is NOT even recommended for experts!
Then why keep it in XML?

Anyway, the problem was not with project file typos; the project file works fine afaict.

The problem is that I don't know how to set up several sub projects within a single project file, if that is even possible in C::B.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7091
    • My Best Post
Re: How do I set include directories per "sub-project" ?
« Reply #8 on: June 13, 2016, 09:43:06 pm »
Hand editing of the CB File is NOT even recommended for experts!
Then why keep it in XML?

Anyway, the problem was not with project file typos; the project file works fine afaict.

The problem is that I don't know how to set up several sub projects within a single project file, if that is even possible in C::B.

USE THE GUI AND ADD NEW TARGETS TO THE PROJECT!!!!!

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 ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #9 on: June 13, 2016, 09:58:25 pm »
USE THE GUI AND ADD NEW TARGETS TO THE PROJECT!!!!!
Wow, why so angry?

I'm still not sure what you are saying; I should add a different target for every "sub-project"? Ok, that might work, feels like abusing the "target" concept logically though.

I think I would still prefer to do that by (programmatically) editing the .cbp XML data; this project has thousands of source files and the C::B GUI only accepts adding ~5 source files at a time unless they already reside in a perfect directory structure, which is not an option when using multiple development environments.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13196
    • Travis build status
Re: How do I set include directories per "sub-project" ?
« Reply #10 on: June 13, 2016, 11:51:21 pm »
Several options:
1. make a single project and multiple targets
2. make multiple projects, make sure every project has the same targets, setup dependencies to order them in the build
3. use custom makefile project and your current Makefile

And for adding file use right click -> add recursively editing the cbp file by hand is doable, but not recommended. Another option is to create the projects using scripting, search the wiki for detail about the api.
(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 ta0

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: How do I set include directories per "sub-project" ?
« Reply #11 on: June 14, 2016, 04:16:14 pm »
Just to check that it's not a terminology confusion, how do I link the produced targets into a single executable?

I'm beginning to think that "sub-projects" was not the correct word; perhaps I should have said "libraries" except they are not really libraries but only parts of the source tree that are compiled separately in the Makefile (because of different compiler settings).

I can not use the regular makefile, even though I'm building with the same compiler, because then the C::B debugger won't follow the source code when stepping.
« Last Edit: June 14, 2016, 04:20:34 pm by ta0 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13196
    • Travis build status
Re: How do I set include directories per "sub-project" ?
« Reply #12 on: June 14, 2016, 08:43:22 pm »
Each target (or project) can produce either static or shared library. These libraries can be linked in the final executable.
(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!]