# Using -d option for compiling causes error

**URL:** <https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [January 2, 2018, 6:48am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925 "2018-01-02T06:48:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 2, 2018, 6:48am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/1 "2018-01-02T06:48:57Z")

</div>

I am trying to use GDB for debugging and as the documentation suggests used -d to generate symbols; I am getting the following error:  
_[5/9] Linking C library_  
\_FAILED: /opt/swi/y17-ext/sysroots/x86\_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi -Wl,–build-id -g -shared -o \_build\_gpioCf3Demo/wp85/staging/read-only/lib/libComponent\_gpioCf3PinComponent.so \_build\_gpioCf3Demo/wp85/component/4087e26d369e060c006ea8351045bd53/obj/e27b33ef46e2835b19e10829a05c1dcb.o \_build\_gpioCf3Demo/wp85/api/de8215af72a76ce25f0abab7714a1199/client/le\_gpioPin25\_client.c.o \_build\_gpioCf3Demo/wp85/component/4087e26d369e060c006ea8351045bd53/obj/\_componentMain.c.o -L\_build\_gpioCf3Demo/wp85/staging/read-only/lib -Wl,–enable-new-dtags,-rpath=“$ORIGIN/…/lib” “-L$LEGATO\_BUILD/framework/lib” -llegato -lpthread -lrt -lm && splitdebug -d dpio\_Debug/ _build\_gpioCf3Demo/wp85/staging/read-only/lib/libComponent\_gpioCf3PinComponent.so_  
\_objcopy: Unable to recognise the format of the input file `_build\_gpioCf3Demo/wp85/staging/read-only/lib/libComponent\_gpioCf3PinComponent.so’_  
_ninja: build stopped: subcommand failed._

Can any one help with this issue ??

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 3, 2018, 9:51pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/2 "2018-01-03T21:51:39Z")

</div>

How are you setting your toolchain? The -d option use the objcopy tool, and it looks like the objcopy that mkTools is trying to use doesn’t match the compiler it’s using. This could occur (for example) if you set either the `CC` or `<target>_CC` environment variables without setting the corresponding `OBJCOPY` variable.

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 5, 2018, 4:34am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/3 "2018-01-05T04:34:46Z")

</div>

@kdunwoody I have installed the arm-poky toolchain as per instructions; it resides in **/opt/swi/** folder; before compiling I source the toolchain and the legato environment.

\_This could occur (for example) if you set either the CC or _CC environment variables without setting the corresponding OBJCOPY variable._

As of now I am not setting anything; the ninja script is generating the **build.config** automatically, and in the build.config, OBJCOPY is assigned to the one which accompanies the arm-poky toolchain. I also tried replacing the original objcopy with a softlink to the arm-poky one with no avail.

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 5, 2018, 4:44am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/4 "2018-01-05T04:44:41Z")

</div>

@kdunwoody How can I manually set the **CC** , **\_CC** and **OBJCOPY**??

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 5, 2018, 4:11pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/5 "2018-01-05T16:11:18Z")

</div>

If you’re not setting these variables manually now, I wouldn’t mess with them. In your case (where you’re using a pre-built toolchain installed in `/opt/swi`), you shouldn’t need to touch these. But if they are defined, mkTools will take compiler, linker, etc. paths from environment variables. How to set environment variables depends on which shell you’re using – check the documentation for your shell.

Are you either running `bin/legs` or sourcing `bin/configlegatoenv` first? If so, can you send me:

- the output of the `env` command
- the _full_ output of whatever mk command you are running.

Preferably in a file attached to your post; the forum software will remove important characters (like \_) if you’re not careful.

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 8, 2018, 6:34am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/6 "2018-01-08T06:34:53Z")

</div>

@kdunwoody Yes I am using a pre-built toolchain; I do source the toolchain environment and the legato environment before using target specific mkapp or make commands. Please find the documents you asked for, attached.  
mkapp without -d option:  
[mk\_LOGS.txt](https://forum.legato.io/uploads/short-url/6vbNa4uDKfDXFJ1tL3PsM40hmaW.txt) (10.7 KB)

mkapp with -d option:  
[mk\_-d\_LOGS.txt](https://forum.legato.io/uploads/short-url/pS6BeRTUfkWUJyTTGMDimxtOsI7.txt) (11.1 KB)

sourcing legato environment:

 ![env](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/1X/a50b3a5fb5bd42e7b582190e33d5c28d88250b9e.PNG)

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 8, 2018, 11:28am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/7 "2018-01-08T11:28:16Z")

</div>

@kdunwoody Just noticed that using **make wp85** in Legato doesnot generate debug symbols in **build/wp85/debug** as the documentation claims. Is this to be expected or could this be related to the issue ?

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 8, 2018, 5:56pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/8 "2018-01-08T17:56:57Z")

</div>

Can you also send me the output of the `env` command?

Are you checking for hidden directories? Debug output is generated into a hidden directory (i.e. actual debug symbols will be in build/wp85/debug/.build-id).

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 9, 2018, 5:52am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/9 "2018-01-09T05:52:47Z")

</div>

@kdunwoody Find the output to the env command attached.

[env\_command.txt](https://forum.legato.io/uploads/short-url/suc0HRaGwRgNYNfS7QqciEcEnjM.txt) (7.2 KB)

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 9, 2018, 4:44pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/10 "2018-01-09T16:44:19Z")

</div>

You have  
WP85\_TOOLCHAIN\_DIR=/opt/swi/y17-ext/sysroots/x86\_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi, but your path starts with PATH=/opt/swi/y17-ext\_1706/sysroots/x86\_64-pokysdk-linux/usr/bin. So I guess stripdebug may be using objcopy from /opt/swi/y17-ext\_1706, but gcc from /opt/swi/y17. Can you try unsetting the OBJCOPY&STRIP environment variables, and remove /opt/swi/y17-ext\_1706 from your path?

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 10, 2018, 5:06am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/11 "2018-01-10T05:06:27Z")

</div>

@kdunwoody

y17-ext is a softlink for y17-ext\_1706[this folder contains the toolchain].

I tried rewriting PATH with only y17-ext and then WP85\_TOOLCHAIN\_DIR with y17-ext\_1706; both had no luck.

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 10, 2018, 10:50am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/12 "2018-01-10T10:50:18Z")

</div>

@kdunwoody It seemed the issue was with the fact that the mkapp was still somehow using /usr/bin/objcopy and /usr/bin/strip; I manually softlinked them to the necessary files and the original error no longer appears;

But now the issue is with the GDB : Please find the logs attached.

[gdb\_log.txt](https://forum.legato.io/uploads/short-url/iT43T3FnzvdAZnzKrYJadHS5inQ.txt) (1.4 KB)

Even though the log says no debug symbols were found I found them in **/Workspace/gpioCf3Demo/dpio\_Debug** [The folder I had given as -d option] as hidden folder as you said earlier.

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 10, 2018, 5:33pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/13 "2018-01-10T17:33:03Z")

</div>

How to use these debug symbols is described in [Debug using GDB - Legato Docs](http://legato.io/legato-docs/latest/howToDebugGDB.html).

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 11, 2018, 5:39am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/14 "2018-01-11T05:39:16Z")

</div>

@kdunwoody I am following those steps; I am attaching my gbd logs; please go through and help me find the issue with the debug symbols loading:

[gdb\_log\_2.txt](https://forum.legato.io/uploads/short-url/7ZbdHRQhXY4AJRDDB7aFUcyB5td.txt) (1.7 KB)

---

<div class="post-metadata">

**Author:** ![kdunwoody](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kdunwoody/32/500_2.png) [@kdunwoody](https://forum.legato.io/u/kdunwoody)\
**Post date:** [January 11, 2018, 5:13pm UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/15 "2018-01-11T17:13:51Z")

</div>

IIRC you have to do `set debug-file-directory /home/febin/Workspace_Gen35/gpioCf3Demo/dpio_Debug` (i.e. no .build-id on the end). Check the gdb docs to be sure though (or just try it).

---

<div class="post-metadata">

**Author:** ![codegit001](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@codegit001](https://forum.legato.io/u/codegit001)\
**Post date:** [January 12, 2018, 4:36am UTC](https://forum.legato.io/t/using-d-option-for-compiling-causes-error/2925/16 "2018-01-12T04:36:16Z")

</div>

Hi @kdunwoody I had to use **add-symbol-file** to manually add **.debug** files to PROGBIT address locations found after using readelf on the binary file generated in the **\_build\_gpioCf3Demo/wp85/app/gpioCf3Demo/staging/read-only/bin/gpioCf3Demo** path.

After this I was able to debug sample apps using GDB and DDD.
