<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Inclusion of user-defined header file in Connect SDK library files</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93882/inclusion-of-user-defined-header-file-in-connect-sdk-library-files</link><description>Hello, I have a need to include a header file that I have defined in one of the Connect SDK .c files. For the purposes of this question, let&amp;#39;s say I want to #include &amp;quot;myfunctionsandvariables.h&amp;quot; in azure_iot_hub.c. An example of my file structure in my</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Nov 2022 17:57:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93882/inclusion-of-user-defined-header-file-in-connect-sdk-library-files" /><item><title>RE: Inclusion of user-defined header file in Connect SDK library files</title><link>https://devzone.nordicsemi.com/thread/396485?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2022 17:57:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ece4259d-aeaf-4183-9caa-ee285e136458</guid><dc:creator>brown27</dc:creator><description>&lt;p&gt;Hi Raoul,&lt;/p&gt;
&lt;p&gt;Like you did, I included the &amp;quot;target_sources&amp;quot; and &amp;quot;include_directories&amp;quot; lines in my src/myproject/myboard/Cmakelists.txt and the &amp;quot;#include &amp;quot;&lt;span&gt;myfunctionsandvariables.h&amp;quot;&amp;quot; line in my main.c. I should have clarified this in my original question. My file structure up above seems to match the structure in your picture, which is good.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let&amp;#39;s say I define &amp;quot;void myfunc(void)&amp;quot; in&amp;nbsp;myfunctionsandvariables.h and&amp;nbsp;myfunctionsandvariables.c. I can successfully call myfunc() in main.c, but I cannot call this function in something like the Connect SDK library&amp;#39;s azure_iot_hub.c or aws_iot.c.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How could I call myfunc() in&amp;nbsp;azure_iot_hub.c or aws_iot.c?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inclusion of user-defined header file in Connect SDK library files</title><link>https://devzone.nordicsemi.com/thread/396484?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2022 17:47:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de4ba5fc-8ec4-4f9d-b142-d0a52816bfe6</guid><dc:creator>Raoul</dc:creator><description>&lt;p&gt;Hi Brown,&lt;/p&gt;
&lt;p&gt;Are you actually trying to create an &amp;quot;external static library&amp;quot;, or are you simply trying to create some header and source files for your project?&lt;/p&gt;
&lt;p&gt;To include files according to the way you described your directory structure, you can update your cmakelists.txt with this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;target_sources(app PRIVATE
    src/main.c
    src/mylib.c
)

include_directories(
    include
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and then add&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;mylib.h&amp;quot;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in your main.c.&lt;/p&gt;
&lt;p&gt;and then place your files like this:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1668793541825v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I have created a zip files of the hello world sample modified to call hello world from a library:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hello_5F00_world_5F00_library.zip"&gt;devzone.nordicsemi.com/.../hello_5F00_world_5F00_library.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Does this answer your question?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Raoul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inclusion of user-defined header file in Connect SDK library files</title><link>https://devzone.nordicsemi.com/thread/395843?ContentTypeID=1</link><pubDate>Tue, 15 Nov 2022 15:46:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52afdf43-d6f5-4843-bd3f-7064af105c5b</guid><dc:creator>brown27</dc:creator><description>&lt;p&gt;Update - I have tried zephyr&amp;#39;s external_lib sample and it works fine. However, when I use that example to build&amp;nbsp;&lt;span&gt;myfunctionsandvariables as an external library, I receive the following error:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;/home/myuser/ncs/zephyr/modules/hal_nordic/nrfx/./nrfx_glue.h:297:10: fatal error: ../src/nrf_802154_peripherals_nrf52.h: No such file or directory
  297 | #include &amp;lt;../src/nrf_802154_peripherals_nrf52.h&amp;gt;
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This error seems to be the result of my &amp;quot;#include &amp;lt;zephyr.h&amp;gt;&amp;quot; statement in&amp;nbsp;myfunctionsandvariables.h.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is this the path that I should be going down to solve my problem? Will building&amp;nbsp;myfunctionsandvariables as an external library allow me to #include it in the ConnectSDK libraries?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>