User forums > General (but related to Code::Blocks)

<solved> how to properly "include" a lib's h file ?

(1/1)

AZ:
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".

stahta01:
.h means it is an header file! It is not an library file!


--- Quote --- a. #include "../path/to/file.h"
 b. #include "file.h"

--- End quote ---
b is better than a in my opinion

Tim S.

AZ:

--- Quote from: 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"

--- End quote ---
b is better than a in my opinion

Tim S.

--- End quote ---

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

stahta01:
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.

AZ:
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!


Navigation

[0] Message Index

Go to full version