Author Topic: <solved> how to properly "include" a lib's h file ?  (Read 7489 times)

Offline AZ

  • Almost regular
  • **
  • Posts: 151
<solved> how to properly "include" a lib's h file ?
« 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".
« Last Edit: August 18, 2020, 10:27:57 pm by AZ »
CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: how to properly "include" a lib ?
« Reply #1 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline AZ

  • Almost regular
  • **
  • Posts: 151
Re: how to properly "include" a lib ?
« Reply #2 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
« Last Edit: August 18, 2020, 06:14:42 am by AZ »
CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: how to properly "include" a lib's h file ?
« Reply #3 on: August 18, 2020, 04:34:23 pm »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline AZ

  • Almost regular
  • **
  • Posts: 151
Re: how to properly "include" a lib's h file ?
« Reply #4 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!


« Last Edit: August 18, 2020, 10:27:34 pm by AZ »
CB: nightly build .
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)