<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>How to create and link a static library for an ARM project using arm-none-eabi-gcc? or get the knoledge to do it</title><link>https://community.arm.com/developer/tools-software/oss-platforms/f/gnu-toolchain-forum/47561/how-to-create-and-link-a-static-library-for-an-arm-project-using-arm-none-eabi-gcc-or-get-the-knoledge-to-do-it</link><description> 
 
 I want to create a static library libmylib.a from mylib.c/.h and link it to a project to use this library in bootloader code using the arm-none-eabi-gcc cross compiler in ubuntu 20.04 LTS. 
 
 
 
 
 I have an electronic engineering background, so</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: How to create and link a static library for an ARM project using arm-none-eabi-gcc? or get the knoledge to do it</title><link>https://community.arm.com/thread/167844?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 22:06:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:87f651a4-17f3-4ec6-b373-0d69899e9b7a</guid><dc:creator>MarcVonWindscooting</dc:creator><description>&lt;p&gt;Pity, no one answered. Had this problem quite a few years ago.&lt;/p&gt;
&lt;p&gt;Assuming ARM7TDMI in ARM moode, you compile to objects with&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arm-none-eabi-gcc -ffreestanding -mcpu=arm7tdmi -marm -c main.c&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Use your processor or arch (e.g. arch=armv8-m) instead.&lt;/p&gt;
&lt;p&gt;You have to create an index in the .a file with ar option -s. I use:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arm-none-eabi-ar rcs libmylib.a *.o

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can use that libmylib.a when linking with ld or better gcc like shown below. Conversion into .bin or .hex is done with objcopy:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;arm-none-eabi-gcc -o program.elf main.o -Lpath/to/lib -lmylib -ffreestanding -nostdlib -lgcc
arm-none-eabi-objcopy --only-section=.text --only-section=.rodata --only-section=.data -O binary program.elf program.bin
arm-none-eabi-objcopy --only-section=.text --only-section=.rodata --only-section=.data -O ihex program.elf program.hex&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Very important and very complex to me was creating a suitable LD-script, which is provided with -T&amp;lt;linkerScript.x&amp;gt; when linking.&lt;/p&gt;
&lt;p&gt;And of course a startup-code (crt0.o) you use from the linker script. But that needs MUCH MORE details of your processor, architecture, etc....&lt;/p&gt;
&lt;p&gt;I&amp;#39;m currently re-programming my build system for bare-metal LPC8/LPC17/LPC21/LPC43/ADSP-CM403 for Linux/RaspberryPi.&lt;/p&gt;
&lt;p&gt;I stopped using make, because I can&amp;#39;t do the things I need with it. If you&amp;#39;re interested in it, let me know.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Marc&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>