<?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>Creating a &amp;quot;system&amp;quot; static lib</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49125/creating-a-system-static-lib</link><description>Hi, 
 
 I&amp;#39;m working on a project where I need for some reason to create a &amp;quot;system&amp;quot; static lib. 
 What I mean by &amp;quot;system&amp;quot; is a lib where all nrf_driver, startup file, etc are grouped in a single .a file. 
 This will be later used by arm-none-eabi-gcc to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 01 Jul 2019 12:34:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49125/creating-a-system-static-lib" /><item><title>RE: Creating a "system" static lib</title><link>https://devzone.nordicsemi.com/thread/195637?ContentTypeID=1</link><pubDate>Mon, 01 Jul 2019 12:34:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3ec69cf-24f1-4042-aa1d-bb8bff9bb4ec</guid><dc:creator>Zoptune</dc:creator><description>&lt;p&gt;Ok so I finally succeed to get the output using the static lib I generated.&lt;/p&gt;
&lt;p&gt;In my last comment I said that all object files in the static lib were not linked.&lt;/p&gt;
&lt;p&gt;To force gcc to link every file in the lib I added the flag &lt;em&gt;&lt;strong&gt;-Wl,--whole-archive&lt;/strong&gt;&lt;/em&gt; before &lt;strong&gt;libnrf52.a&lt;/strong&gt;. Now we can see that the linker links all objects from the static lib : &lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;attempt to open libnrf52.a succeeded
(libnrf52.a)app_error.c.o
(libnrf52.a)app_error_weak.c.o
(libnrf52.a)app_fifo.c.o
(libnrf52.a)app_uart_fifo.c.o
(libnrf52.a)app_util_platform.c.o
(libnrf52.a)boards.c.o
(libnrf52.a)gcc_startup_nrf52840.S.o
(libnrf52.a)nrf_assert.c.o
(libnrf52.a)nrf_balloc.c.o
(libnrf52.a)nrf_drv_common.c.o
(libnrf52.a)nrf_drv_uart.c.o
(libnrf52.a)nrf_log_frontend.c.o
(libnrf52.a)nrf_memobj.c.o
(libnrf52.a)nrf_strerror.c.o
(libnrf52.a)retarget.c.o
(libnrf52.a)system_nrf52840.c.o&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I also added the &lt;em&gt;&lt;strong&gt;-Wl,--no-whole-archive&lt;/strong&gt;&lt;/em&gt; after the library that other libraries won&amp;#39;t be affected. The final gcc command is the following :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arm-none-eabi-gcc -O3 -mthumb -mabi=aapcs -L ../../../../../../components/toolchain/gcc -Tuart_gcc_nrf52.ld -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs main.c.o -Wl,--whole-archive libnrf52.a -Wl,--no-whole-archive -o nrf52840_xxaa.out&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Creating a "system" static lib</title><link>https://devzone.nordicsemi.com/thread/195605?ContentTypeID=1</link><pubDate>Mon, 01 Jul 2019 11:24:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfbdc06a-0845-4831-abb7-6e14067a87a0</guid><dc:creator>Zoptune</dc:creator><description>&lt;p&gt;In order to get more debug information, I added the &lt;em&gt;&lt;strong&gt;-Wl,--verbose&lt;/strong&gt;&lt;/em&gt; flag to the linking step for both Makefile and manual linking with static lib.&lt;/p&gt;
&lt;p&gt;Then I compared the outputs and I found that when I use the static lib, not all the object files in the archive are used for linking.&lt;/p&gt;
&lt;p&gt;Here are the files loaded during linking with the Makefile :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;_build/nrf52840_xxaa/nrf_log_frontend.c.o
_build/nrf52840_xxaa/boards.c.o
_build/nrf52840_xxaa/app_error.c.o
_build/nrf52840_xxaa/app_error_weak.c.o
_build/nrf52840_xxaa/app_fifo.c.o
_build/nrf52840_xxaa/app_uart_fifo.c.o
_build/nrf52840_xxaa/app_util_platform.c.o
_build/nrf52840_xxaa/nrf_assert.c.o
_build/nrf52840_xxaa/nrf_balloc.c.o
_build/nrf52840_xxaa/nrf_memobj.c.o
_build/nrf52840_xxaa/nrf_strerror.c.o
_build/nrf52840_xxaa/retarget.c.o
_build/nrf52840_xxaa/nrf_drv_common.c.o
_build/nrf52840_xxaa/nrf_drv_uart.c.o
_build/nrf52840_xxaa/main.c.o
_build/nrf52840_xxaa/gcc_startup_nrf52840.S.o
_build/nrf52840_xxaa/system_nrf52840.c.o&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And here are the files loaded during manual linking with the static lib :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;attempt to open main.c.o succeeded
main.c.o
attempt to open libnrf52.a succeeded
(libnrf52.a)app_error.c.o
(libnrf52.a)app_error_weak.c.o
(libnrf52.a)app_uart_fifo.c.o
(libnrf52.a)boards.c.o
(libnrf52.a)gcc_startup_nrf52840.S.o
(libnrf52.a)nrf_drv_uart.c.o
(libnrf52.a)system_nrf52840.c.o
(libnrf52.a)app_fifo.c.o
(libnrf52.a)nrf_drv_common.c.o&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why not every files are loaded.&lt;/p&gt;
&lt;p&gt;Does someone has any idea ?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Creating a "system" static lib</title><link>https://devzone.nordicsemi.com/thread/195583?ContentTypeID=1</link><pubDate>Mon, 01 Jul 2019 10:22:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d27fc15-c3ad-466c-b362-cb8bae7ce6b7</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Yes, I&amp;#39;d have thought it should be &lt;em&gt;possible&lt;/em&gt; - you&amp;#39;re just going to have to search out how to actually do it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Creating a "system" static lib</title><link>https://devzone.nordicsemi.com/thread/195582?ContentTypeID=1</link><pubDate>Mon, 01 Jul 2019 10:20:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2cee435-b1e5-4df3-9df9-ac159939423a</guid><dc:creator>Zoptune</dc:creator><description>&lt;p&gt;Hi and thanks for your answer.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think that&amp;#39;s a problem because a static lib is just a bunch of object files right ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Creating a "system" static lib</title><link>https://devzone.nordicsemi.com/thread/195371?ContentTypeID=1</link><pubDate>Fri, 28 Jun 2019 12:55:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9a0ec60-e782-49ea-9f75-b1a1788c7852</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;can you debug into a GCC static library?&lt;/p&gt;
&lt;p&gt;you&amp;#39;ll need to do some googling to find out ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>