# Ldflag -L in cdef

**URL:** <https://forum.legato.io/t/ldflag-l-in-cdef/5585>\
**Category:** VSCode\
**Created:** [January 24, 2021, 5:03am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585 "2021-01-24T05:03:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![french](https://avatars.discourse-cdn.com/v4/letter/f/7ea924/32.png) [@french](https://forum.legato.io/u/french)\
**Post date:** [January 24, 2021, 5:03am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585/1 "2021-01-24T05:03:04Z")

</div>

I am currently trying to use the vscode plugin to build my app that uses a third party .so file (sqlite to exact). I am using the ldflag command in my .cdef to include the .so. However this doesn’t seem to work and complains about undefined references.

Automated vscode build output

```
> Executing task: mkapp ${LEGATO_DEF_FILE} -s components -t ${LEGATO_TARGET} -w ${LEGATO_OBJECT_DIR} -o ${LEGATO_OUTPUT_DIR} <

[1/1] Regenerating build script
[6/9] Linking C executable
FAILED: /home/french/leaf/_build_SQLiteDemo/wp77xx/app/SQLiteDemo/obj/SQLiteDemoComponentExe/SQLiteDemoComponentExe 
/home/french/leaf/leaf-data/dev/wp77-toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/home/french/leaf/leaf-data/dev/wp77-toolchain/sysroots/armv7a-neon-poky-linux-gnueabi -fPIE -pie -o /home/french/leaf/_build_SQLiteDemo/wp77xx/app/SQLiteDemo/obj/SQLiteDemoComponentExe/SQLiteDemoComponentExe /home/french/leaf/_build_SQLiteDemo/wp77xx/app/SQLiteDemo/obj/SQLiteDemoComponentExe/_main.c.o -rdynamic -Wl,--enable-new-dtags,-rpath="\$ORIGIN/../lib" -L "-L/home/french/leaf/_build_SQLiteDemo/wp77xx/component/652a9d5bf0d55627ce7e6178f2524356/obj" -lComponent_SQLiteDemoComponent -L /home/french/leaf/leaf-data/dev/wp77-legato/3rdParty/sqlite/lib/sqlite3.so "-L/home/french/leaf/_build_SQLiteDemo/wp77xx/component/652a9d5bf0d55627ce7e6178f2524356/obj" -lComponent_SQLiteDemoComponent -L /home/french/leaf/leaf-data/dev/wp77-legato/3rdParty/sqlite/lib/sqlite3.so "-L$LEGATO_BUILD/framework/lib" -llegato -lpthread -lrt -ldl -lm 
/home/french/leaf/_build_SQLiteDemo/wp77xx/component/652a9d5bf0d55627ce7e6178f2524356/obj/libComponent_SQLiteDemoComponent.so: undefined reference to `sqlite3_libversion'
/home/french/leaf/_build_SQLiteDemo/wp77xx/component/652a9d5bf0d55627ce7e6178f2524356/obj/libComponent_SQLiteDemoComponent.so: undefined reference to `sqlite3_open'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The terminal process "/bin/bash '-c', 'mkapp ${LEGATO_DEF_FILE} -s components -t ${LEGATO_TARGET} -w ${LEGATO_OBJECT_DIR} -o ${LEGATO_OUTPUT_DIR}'" failed to launch (exit code: 1).

```

component.cdef

```
// SQLiteDemoComponent
//
// This is component definition file that specifies the internal content and external interfaces
// of reusable software components.
//
// For more details on the component definition (.cdef) file format see:
// https://docs.legato.io/latest/defFilesCdef.html

// Source code files.
sources:
{
    SQLiteDemoComponent.c
   
}

ldflags:
{
   -L ${LEGATO_ROOT}/3rdParty/sqlite/lib/sqlite3.so
}

// Bind resources from the target module into your application.
requires:
{
    // IPC APIs used by this component.
    api:
    {
         
    }
    
    // File paths local to your target module.
    file:
    {
    }
    
    // Directories on your target module to make accessible to the app.
    dir:
    {
    }
    
    // Linux filesystem device paths.
    device:
    {
    }
    
    // Shared libraries pre-installed on the module.
    lib:
    {
    }
}

```

SQLiteDemo.adef

```
sandboxed: false

// Specify the bundled components for your application here. This section needs to contain a list
// of system paths to your component directory.
components:
{
}

// Add the list of executables to be constructed and moved to the /bin directory of the app. The
// executable content is a list of the components inside the executable.
//
// Example binding format:
// clientExe.clientComponent.clientInterface -> serverExe.serverComponent.serverInterface
executables:
{
    SQLiteDemoComponentExe = ( SQLiteDemoComponent )
}

// The processes section specifies processes to run when the app is started including environment
// variables, command-line arguments, limits, and fault handling actions.
processes:
{
    run:
    {
        ( SQLiteDemoComponentExe )
    }
}

// Bindings that allow client side API interfaces to be bound to servers found within other
// applications in the system.
bindings:
{
}

bundles:
{
    file:
    {
        [r] ${LEGATO_ROOT}/3rdParty/sqlite/lib/sqlite3.so /lib/
    }
    
}

```

If I run the mkapp command manually I get a successfull build and can upload and run the .update file so I am fairly certain everyting is as it should be.

```
$ mkapp ${LEGATO_DEF_FILE} -s components -t ${LEGATO_TARGET} -w ${LEGATO_OBJECT_DIR} -o ${LEGATO_OUTPUT_DIR} -L ${LEGATO_ROOT}/3rdParty/sqlite/lib/sqlite3.so 
[9/9] Packaging app

```

Am i wrong in expecting adding the -L in the cdef file will have the same effect as if I was to manually add it to the command? Or is there something I dont understand correctly.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [January 24, 2021, 5:23am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585/2 "2021-01-24T05:23:53Z")

</div>

You can see here, it used “lib” section:

> [@Problems with using libxml2](https://forum.legato.io/t/problems-with-using-libxml2/5521/27):
>
> I treid that but still got the undefined reference error frowning in cflags i now have have this: cflags: { //-I /home/reinhard/.leaf/wp85-toolchain\_SWI9X15Y\_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2/include/ -I /home/reinhard/.leaf/wp76-toolchain\_SWI9X07Y\_02.37.07.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2 }

---

<div class="post-metadata">

**Author:** ![french](https://avatars.discourse-cdn.com/v4/letter/f/7ea924/32.png) [@french](https://forum.legato.io/u/french)\
**Post date:** [January 24, 2021, 7:04am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585/3 "2021-01-24T07:04:57Z")

</div>

thanks @jyijyi, i added path of the .so to the lib section in my .cdef and it compiles now. I did have to change the file name from sqlite3.so to libsqlite3.so but it worked.

```
// Shared libraries pre-installed on the module.
lib:
{
    /lib/libsqlite3.so
}

```

But now the app wont run on my module as it cant find the library (this is not an issue when compiled manually using mkapp). I changed the local file name to libsqlite3 and adjusted the .adef file to suit. I can confirm the file is bundled and uploaded.

```
root@swi-mdm9x28-wp:/legato/apps/49abaf98c3c8e366e4250a5d652a0737# ls read-only/lib/
libComponent_SQLiteDemoComponent.so libsqlite3.so sqlite3.so 

```

App start error message,

```
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c app_Start() 3471 | Starting app 'SQLiteDemo'
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c CreateFileLink() 2084 | Skipping file link '/legato/systems/current/apps/SQLiteDemo/read-only/lib/libComponent_SQLiteDemoComponent.so' to '/legato/systems/current/appsWriteable
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c CreateFileLink() 2084 | Skipping file link '/legato/systems/current/apps/SQLiteDemo/read-only/lib/sqlite3.so' to '/legato/systems/current/appsWriteable/SQLiteDemo/lib/sqlite3.s
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c CreateFileLink() 2084 | Skipping file link '/legato/systems/current/apps/SQLiteDemo/read-only/lib/libsqlite3.so' to '/legato/systems/current/appsWriteable/SQLiteDemo/lib/libsql
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c CreateFileLink() 2084 | Skipping file link '/legato/systems/current/apps/SQLiteDemo/read-only/bin/SQLiteDemoComponentExe' to '/legato/systems/current/appsWriteable/SQLiteDemo/b
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c CreateFileLink() 2084 | Skipping file link '/legato/systems/current/apps/SQLiteDemo/read-only/lib/libsqlite3.so' to '/legato/systems/current/appsWriteable/SQLiteDemo/lib/libsql
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | proc.c proc_Start() 1403 | Starting process 'SQLiteDemoComponentExe' with pid 6015
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[6015]/supervisor T=main | proc.c proc_Start() 1363 | Execing 'SQLiteDemoComponentExe'
Jan 10 07:26:27 swi-mdm9x28-wp user.err Legato: =ERR= | SQLiteDemoComponentExe[6015] | SQLiteDemoComponentExe: error while loading shared libraries: libsqlite3.so.0: cannot open shared object file: No such file or directory
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | proc.c proc_SigChildHandler() 2079 | Process 'SQLiteDemoComponentExe' (PID: 6015) has exited with exit code 127.
Jan 10 07:26:27 swi-mdm9x28-wp user.warn Legato: -WRN- | supervisor[2089]/supervisor T=main | app.c app_SigChildHandler() 4066 | Process 'SQLiteDemoComponentExe' in app 'SQLiteDemo' faulted: Ignored.
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | app.c app_StopComplete() 4753 | app 'SQLiteDemo' has stopped.
Jan 10 07:26:27 swi-mdm9x28-wp user.info Legato: INFO | supervisor[2089]/supervisor T=main | apps.c DeactivateAppContainer() 374 | Application 'SQLiteDemo' has stopped.

```

I assume it is now looking in the wrong file system?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [January 24, 2021, 7:16am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585/4 "2021-01-24T07:16:38Z")

</div>

It needs libsqlite3.so.0  
Maybe you need to make one more copy to have this library file

---

<div class="post-metadata">

**Author:** ![french](https://avatars.discourse-cdn.com/v4/letter/f/7ea924/32.png) [@french](https://forum.legato.io/u/french)\
**Post date:** [January 25, 2021, 9:29am UTC](https://forum.legato.io/t/ldflag-l-in-cdef/5585/5 "2021-01-25T09:29:22Z")

</div>

Ok cool. All working now thank you.

I did have to recompile my lib as a real shared lib (using -shared instead of -c ).
