Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: AZ on August 17, 2020, 08:54:02 pm

Title: <solved> how to properly "include" a lib's h file ?
Post by: AZ on August 17, 2020, 08:54:02 pm
hello,
 what is the proper syntax to include a lib's h file:
 a. #include "../path/to/file.h"
 b. #include "file.h"

platformio specifies a full path to library/src for all libs used in the project and, as such, all i should type is "file.h".
Title: Re: how to properly "include" a lib ?
Post by: stahta01 on August 18, 2020, 02:50:16 am
.h means it is an header file! It is not an library file!

Quote
a. #include "../path/to/file.h"
 b. #include "file.h"
b is better than a in my opinion

Tim S.
Title: Re: how to properly "include" a lib ?
Post by: AZ on August 18, 2020, 06:13:05 am
.h means it is an header file! It is not an library file!

Quote
a. #include "../path/to/file.h"
 b. #include "file.h"
b is better than a in my opinion

Tim S.

Tim,
 the correction is well taken. I updated the thread accordingly.

to go with "b", what do i need to configure in CB? by default, it is throwing "file not found" during the compilation. For simplicity, lets say i have the following project structure:
proj name
 - src
     main.cpp
 - lib
     library_name
           lib.h
  - include
Title: Re: how to properly "include" a lib's h file ?
Post by: stahta01 on August 18, 2020, 04:34:23 pm
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#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 (http://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#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)

Do not use the "For global environment" section.
Do use the "For your project" section.

Edit: Including headers are compiler options.

Tim S.
Title: Re: how to properly "include" a lib's h file ?
Post by: AZ on August 18, 2020, 06:05:12 pm
That is exactly how i went about it https://imgur.com/XqHqg7W.png
though it is odd that the directories are not been propagated into targets: https://imgur.com/CAToKGc.png
yet I added the directory to both targets. CB still doesn't show them in the autocomplete:
https://imgur.com/xBiAi4d.png


Aha, Bingo! to have the autocomplete to work properly:
0. follow the link Tim suggested above.
1. in the "search directories" (project level, not "target") specify path _to_ the H/HPP files.
2. "save" the project. "reparse" the project.
3. HPP files do not get into autocompletion for "include", but they are parsed, so the code autocomplete uses the classes from them.

Thank you Tim!