Ldflag -L in cdef

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.

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

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?

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

Ok cool. All working now thank you.

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