# Gnat arm elf 12.2.1 (alire) undefined reference to strlen

**URL:** https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277
**Category:** General
**Tags:** embedded
**Created:** [December 29, 2022, 7:33pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277 "2022-12-29T19:33:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/40_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)
#### Post date: [December 29, 2022, 7:33pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/1 "2022-12-29T19:33:48Z")

</div>

Merry xmas all.

I simplified my Last Chance Handler by using

Interfaces.C.Strings.Value

The compiler output undefined reference to ‘strlen’

light-cortex-m4f/adalib/libgnat.a(i-cstrin.o)

I could go back to my manual string null termination finding function. Or should I look into Gnat. Could someone point me to the right place to report and or submit a patch (is it gerrit that GCC uses or something)?

---

<div class="post-metadata">

### Author: ![stephe-ada-guru](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/stephe-ada-guru/32/77_2.png) [@stephe-ada-guru](https://forum.ada-lang.io/u/stephe-ada-guru)
#### Post date: [January 1, 2023, 3:45pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/2 "2023-01-01T15:45:23Z")

</div>

Please show the full link command line - it’s either missing the C library that contains strlen, or it’s in the wrong order.

This is most likeley a packaging issue, so the place to submit an issue is [GitHub - alire-project/GNAT-FSF-builds: Builds of the GNAT Ada compiler from FSF GCC releases](https://github.com/alire-project/GNAT-FSF-builds)

---

<div class="post-metadata">

### Author: ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/40_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)
#### Post date: [January 1, 2023, 5:33pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/3 "2023-01-01T17:33:46Z")

</div>

Is this that I had kept, enough? I might actually be happier with my own solution now but happy to revert it if more is needed.

/home/kc/.config/alire/cache/dependencies/gnat\_arm\_elf\_12.2.1\_9be2ca0e/bin/…/lib/gcc/arm-eabi/12.2.0/…/…/…/…/arm-eabi/bin/ld: /home/kc/.config/alire/cache/dependencies/gnat\_arm\_elf\_12.2.1\_9be2ca0e/arm-eabi/lib/gnat/light-cortex-m4f/adalib/libgnat.a(i-cstrin.o): in function `interfaces __c__ strings__value': i-cstrin.adb:(.text.interfaces__c __strings__ value+0xe): undefined reference to `strlen’

---

<div class="post-metadata">

### Author: ![simonjwright](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/simonjwright/32/11_2.png) [@simonjwright](https://forum.ada-lang.io/u/simonjwright)
#### Post date: [January 1, 2023, 10:30pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/4 "2023-01-01T22:30:50Z")

</div>

You could try adding `-lc` to your linker switches (that runtime seems not to include libc by default, see `runtime.xml`).

I had a look at the object file, can’t see any reason why it’d want `_strlen`, and disassembling the object doesn’t show it as undefined. Baffled.

---

<div class="post-metadata">

### Author: ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/40_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)
#### Post date: [January 3, 2023, 1:14pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/5 "2023-01-03T13:14:20Z")

</div>

Thanks for your efforts Simon. -lc doesn’t seem to have any affect on the output. I shall try not to bring this up again (now getting deja vu about bringing this up previously).

I do see a -nolibc flag at the last stage when building my project. I would rather keep libc away if possible anyway, so not sure if I caused that or not but I can’t see where currently.

I am happy to move on but I have saved the output, if you would like to see it?

---

<div class="post-metadata">

### Author: ![simonjwright](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/simonjwright/32/11_2.png) [@simonjwright](https://forum.ada-lang.io/u/simonjwright)
#### Post date: [January 3, 2023, 11:08pm UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/6 "2023-01-03T23:08:48Z")

</div>

I found out a lot more about this: see [this issue](https://github.com/alire-project/GNAT-FSF-builds/issues/45).

You could try adding your own System.Strlen (s-strlen.ad[bs]), on the lines of `s-memcpy` - could perhaps just copy over the loop part of the implementation from `i-cstrin`?

But then, using your own implementation seems a pretty good solution too!

---

<div class="post-metadata">

### Author: ![kevlar700](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/kevlar700/32/40_2.png) [@kevlar700](https://forum.ada-lang.io/u/kevlar700)
#### Post date: [January 4, 2023, 12:33am UTC](https://forum.ada-lang.io/t/gnat-arm-elf-12-2-1-alire-undefined-reference-to-strlen/277/7 "2023-01-04T00:33:35Z")

</div>

Crazy. I might have to call you Sherlock from now on!
