News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

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

Started by AZ, August 17, 2020, 08:54:02 PM

Previous topic - Next topic

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".
CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)

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"
b is better than a in my opinion

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

AZ

#2
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"
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
CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

AZ

#4
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!


CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)