Author Topic: #include MACRO, C::B can't detect dependency  (Read 314 times)

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 31
#include MACRO, C::B can't detect dependency
« on: February 27, 2018, 03:36:41 pm »
I have a source file similar to this:

#include "opt.h"
#include INCLUDE_FILENAME


In #include <opt.h> there's something similar to:

#include "user_opt.h"
#ifndef INCLUDE_FILENAME
#  define INCLUDE_FILENAME   "include.h"
#endif


It seems C::B isn't able to detect that .c file depends on include.h too. If I change something in "include.h" only, the build process doesn't anything.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5028
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: #include MACRO, C::B can't detect dependency
« Reply #1 on: February 27, 2018, 03:47:17 pm »
You are correct, that is a limitation in our compiler plugin. You can have a look at the Code::Blocks' source code to understand how the dependency is calculated. It is in the folder src\plugins\compilergcc\depslib. Can you find a better way to do it?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: #include MACRO, C::B can't detect dependency
« Reply #2 on: February 27, 2018, 04:03:05 pm »
Why not add a setting with a command that creates a .depend file that C::B will look during building?
I think many compilers have an option to create a dependecy file that is completely correct.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6221
    • My Best Post
Re: #include MACRO, C::B can't detect dependency
« Reply #3 on: February 28, 2018, 01:41:01 am »
I am guessing external dependency in code::blocks would not do what you want; but, did you try it to be sure?

Edit: I just recalled external dependency is a linker dependency; and, you likely need an compiler dependency.

Tim S.
« Last Edit: February 28, 2018, 02:28:27 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6221
    • My Best Post
Re: #include MACRO, C::B can't detect dependency
« Reply #4 on: February 28, 2018, 02:47:17 am »
You are correct, that is a limitation in our compiler plugin. You can have a look at the Code::Blocks' source code to understand how the dependency is calculated. It is in the folder src\plugins\compilergcc\depslib. Can you find a better way to do it?

So for, I have found "plugins\compilergcc\directcommands.cpp" tends to be the file that calls the depslib functions.

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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5028
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: #include MACRO, C::B can't detect dependency
« Reply #5 on: February 28, 2018, 03:29:26 am »
You are correct, that is a limitation in our compiler plugin. You can have a look at the Code::Blocks' source code to understand how the dependency is calculated. It is in the folder src\plugins\compilergcc\depslib. Can you find a better way to do it?

So for, I have found "plugins\compilergcc\directcommands.cpp" tends to be the file that calls the depslib functions.

Tim S.
Correct, if I remember correctly, the depslib just scan each file for some pattern like
Code: [Select]
#include <xxx.h>
or
#include "xxx.h"
And put the xxx.h as the dependency of the current file. It does not use the preprocessor to handle all the sources.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.