# Undefined reference when using mksys, but not mkapp

**URL:** <https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550>\
**Category:** Uncategorized\
**Created:** [July 13, 2023, 1:59pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550 "2023-07-13T13:59:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 13, 2023, 1:59pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/1 "2023-07-13T13:59:09Z")

</div>

I have created an app using sqlite3 library. The app works as expected and i have had no problems using mkapp and its update file. When i am trying to use mksys instead, to link three apps together, i am getting error saying “undefined reference to …”.

To use sqlite I created a sqlite.so file using gcc and flags like lpthread. One of the undefined references seems to be pthread. Does anyone know why this becomes a problem when using mksys but not mkapp?

---

<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:** [July 13, 2023, 2:09pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/2 "2023-07-13T14:09:00Z")

</div>

how about embed the application to legato.cwe?

> [@Flash size wp7607](https://forum.legato.io/t/flash-size-wp7607/3805/35):
>
> you can go to legato-19.02.0/modules/WiFi/wifi.sdef, under “apps:” section, add e.g. $LEGATO\_ROOT/apps/sample/helloWorld/helloWorld.adef [image] Now the new app will be included in legato.cwe. Please also note that the max size for legato partition is 8MB.

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 7:50am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/3 "2023-07-14T07:50:34Z")

</div>

I still get the same error after adding .adef to wifi.sdef. Here is how the error is shown:

`checking whether the C compiler works... no`  
`configure: error: in /home/sindrekvande/LegatoWorkspace/ths_gw_system/_build_neuronEthernetLteGW/wp76xx/component/37b16d9818aa215e8b1d383409c34f3c/lighttpd:`  
`configure: error: C compiler cannot create executables`  
`See config.log for more details`  
`ninja: build stopped: subcommand failed.`

By looking in config.log i can see “undefined reference to (for example pthread functions)”. Could this mean that i have added the sqlite3 library wrong? Sqlite3 uses pthread library, so when I created sqlite3.so I used gcc and flags like lptrhread. Using this file worked well using mkapp. Using mksys it seems like it finds a reference to the used sqlite3 functions, but not libraries which is included in the sqlite3 library.

---

<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:** [July 14, 2023, 8:26am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/4 "2023-07-14T08:26:24Z")

</div>

when you do mksys, did you together make the “libsqlite3.so”?  
I remember when I build the “libsqlite3.so”, I need to add "-lpthread " in the Makefile.

Or your .adef and .cdef just add bundling of the libsqlite3.so?  
e.g.

```auto

.adef 
bundles:
	{
	file:
	{
	[r] third-party/lib/libsqlite3.so /lib/
	}
	}

.cdef:

requires:
{
    
    lib:
    {
        ../third-party/lib/libsqlite3.so
    }
}

```

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 8:45am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/5 "2023-07-14T08:45:08Z")

</div>

When i do mksys i use the same “libsqlite3.so” as i created for mkapp. I created it like this:

```auto
export TOOLCHAIN_DIR:=/opt/swi/SWI9X07Y_02.37.07.00/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi

GCC = ${TOOLCHAIN_DIR}/arm-poky-linux-gnueabi-gcc

all:
		${GCC} -c -Wall -Werror -fpic -lpthread -ldl sqlite3.c -I/opt/swi/SWI9X07Y_02.37.07.00/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include -o ../lib/sqlite3.so

```

I have the bundles section in .adef just as like you show, but I do not have a requires section in .cdef, could this be a problem? When using mksys i am running this makefile:

```auto
export WORKSPACE_ROOT = /home/$(USER)/LegatoWorkspace

MKSYS_ARGS_COMMON = -s $(WORKSPACE_ROOT)/apps/GpioExpander/gpioExpanderService
MKSYS_ARGS_MQTT = -s $(WORKSPACE_ROOT)/apps/iotGw/
MKSYS_ARGS_NEURON_MQTT = -s $(WORKSPACE_ROOT)/apps/neuron_iotgw/
MKSYS_ARGS_GMQTT = -s $(WORKSPACE_ROOT)
MKSYS_ARGS_LEGATO = -s $(LEGATO_ROOT)

.PHONY: all
all: green_wp85 green_wp750x green_wp76xx red_wp85 red_wp750x red_wp76xx

.PHONY: neuronEthernetLteGw_wp76xx
neuronethernetltegw_wp76xx:
	mksys -t wp76xx $(MKSYS_ARGS_NEURON_MQTT) \
			-i $(WORKSPACE_ROOT)/apps/neuron_iotgw/sqlite3/inc \
			-L $(WORKSPACE_ROOT)/apps/neuron_iotgw/sqlite3/lib/sqlite3.so \
			neuronEthernetLteGW.sdef

.PHONY: clean
clean:
	rm -rf \
		_build_neuronGW \
		_build_thsGW \
		_build_gmqtt \
		_build_neuronGW2 \
		_build_neuronEthernetLteGW \
		_build_default \
		neuronGW.wp85.update \
		neuronGW.wp76xx.update \
		neuronEthernetLteGW.wp76xx.update \
		neuronGW.wp750x.update \
		neuronGW.wp77xx.update \
		neuronGW2.wp85.update \
		neuronGW2.wp750x.update \
		neuronGW2.wp76xx.update \
		neuronGW2.wp77xx.update \
		gmqtt.wp85.update \
		gmqtt.wp750x.update \
		gmqtt.wp76xx.update \
		gmqtt.wp77xx.update \
		thsGW.wp85.update \
		thsGW.wp76xx.update \
		default.wp76xx.update \
		thsGW.wp77xx.update

```

---

<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:** [July 14, 2023, 8:51am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/6 "2023-07-14T08:51:53Z")

</div>

```auto
`checking whether the C compiler works... no`
`configure: error: in /home/sindrekvande/LegatoWorkspace/ths_gw_system/_build_neuronEthernetLteGW/wp76xx/component/37b16d9818aa215e8b1d383409c34f3c/lighttpd:`
`configure: error: C compiler cannot create executables`
`See config.log for more details`
`ninja: build stopped: subcommand failed.`

```

your error in “make wp76xx” is related to lighttpd…  
Not sqilte stuff

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 9:17am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/7 "2023-07-14T09:17:03Z")

</div>

Yes, but if i remove the parts where I use the sqlite3 the makefile works as expected

---

<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:** [July 14, 2023, 9:20am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/8 "2023-07-14T09:20:54Z")

</div>

then you can modify adef and cdef to see which line makes the problem

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 10:29am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/9 "2023-07-14T10:29:31Z")

</div>

Sorry, I showed only one of the errors. Here is the first error, and why I think it is sqlite aswell.

```auto
/home/sindrekvande/LegatoWorkspace/apps/neuron_iotgw/sqlite3/lib/sqlite3.so
checking for doxygen... :
checking for etags... /bin/false
checking whether make sets $(MAKE)... yes
checking for arm-poky-linux-gnueabi-gcc... /home/sindrekvande/LegatoWorkspace/leaf-data/SWI-WP76/wp76-toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
checking whether the C compiler works... no
configure: error: in `/home/sindrekvande/LegatoWorkspace/ths_gw_system/_build_neuronEthernetLteGW/wp76xx/component/6becee7effb92d59694c69ef7da8fce7':
configure: error: C compiler cannot create executables
See `config.log' for more details

```

---

<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:** [July 14, 2023, 10:42am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/10 "2023-07-14T10:42:42Z")

</div>

Can you try with this app to embed in legato image?

> **[Database Support](https://mangoh.discourse.group/t/database-support/93/71)**
>
> I can compile with attached application. The makefile of sqlite is using WP76 R9 toolchain. The legato application is successfully compiled in WP76 R10.1. testsql.7z (2.8 MB)

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 11:14am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/11 "2023-07-14T11:14:39Z")

</div>

If you mean using the makefile by that, here are the results with your app:

```auto
/home/sindrekvande/LegatoWorkspace/testsql/third-party/lib/libsqlite3.so: In function `sqlite3_global_recover':
sqlite3.c:(.text+0xd2748): multiple definition of `sqlite3_global_recover'
/home/sindrekvande/LegatoWorkspace/testsql/third-party/lib/libsqlite3.so:sqlite3.c:(.text+0xd2748): first defined here
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Makefile:37: recipe for target 'target' failed
make: *** [target] Error 1

```

I also tried to make .so again, but it did not work.

```auto
/opt/swi/y22-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -c -Wall -Werror -fpic -lpthread -ldl sqlite3.c -o ../lib/libsqlite3.so
make: /opt/swi/y22-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc: Command not found
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 127

```

Seems like doesnt exits arm-poky-linux-gnueabi-gcc

---

<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:** [July 14, 2023, 11:21am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/12 "2023-07-14T11:21:04Z")

</div>

Of course you need to install toolchain …

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 11:23am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/13 "2023-07-14T11:23:37Z")

</div>

I was sure I did that, but probably not the right way. Will do that again

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 12:29pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/14 "2023-07-14T12:29:51Z")

</div>

I had installed toolchain, but I had different path and had to add include map to get stdio.h, to make .so. Trying to make the app gives following error now.

```auto
/bin/sh: 1: arm-poky-linux-gnueabi-gcc: not found
ninja: build stopped: subcommand failed.

```

---

<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:** [July 14, 2023, 12:38pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/15 "2023-07-14T12:38:44Z")

</div>

Did you modify the makefile

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 12:40pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/16 "2023-07-14T12:40:16Z")

</div>

Yes, to be able to make. Not the makefile for the app. but sqlite.so

```auto
export TOOLCHAIN_DIR:=/opt/swi/SWI9X07Y_02.37.07.00/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi

GCC = ${TOOLCHAIN_DIR}/arm-poky-linux-gnueabi-gcc

all:
		${GCC} -c -Wall -Werror -fpic -lpthread -ldl sqlite3.c -I/opt/swi/SWI9X07Y_02.37.07.00/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include -o ../lib/sqlite3.so

```

---

<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:** [July 14, 2023, 1:02pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/17 "2023-07-14T13:02:26Z")

</div>

Then why it cannot find the compiler?

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 14, 2023, 1:04pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/18 "2023-07-14T13:04:23Z")

</div>

Weird, I am using the vscode plugin.

---

<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:** [July 14, 2023, 1:28pm UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/19 "2023-07-14T13:28:19Z")

</div>

This should be just run in normal terminal, not related any vscode stuff

No problem is found on my side to compile “libsqlite3.so”:

```auto
owner@ubuntu:~/legato/workspace/testsql/third-party/src$ make
/opt/swi/y22-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -c -Wall -Werror -fpic -lpthread -ldl sqlite3.c -o ../lib/libsqlite3.so
owner@ubuntu:~/legato/workspace/testsql/third-party/src$ ls /opt/swi/y22-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
/opt/swi/y22-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc

```

---

<div class="post-metadata">

**Author:** ![sikva](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sikva](https://forum.legato.io/u/sikva)\
**Post date:** [July 17, 2023, 11:19am UTC](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550/20 "2023-07-17T11:19:30Z")

</div>

I can now run your app if I edit component.cdef and the makefile in Target\_Legato\_Debug. But same problems with mksys.

Had to comment out the added lib in component.cdef:

```auto
sources:
{
	testsqlComponent.c
}

requires:
{
    
    lib:
    {
        //../third-party/lib/libsqlite3.so
    }
}

```

Added to the makefile on mkapp line:  
-i $(CURDIR)/…/third-party/inc -L $(CURDIR)/…/third-party/lib/libsqlite3.so

```auto
#
# AUTO-GENERATED Makefile; do not edit, changes will be lost
#

# Define target type
TARGET:=wp76xx

# Custom makefile include: initialization
-include ../customInit.mk

# Only when not cleaning
ifneq ($(MAKECMDGOALS),clean)
endif

# Target artifact.*
TARGET_ARTIFACT:=testsql.$(TARGET).update

# Clean command
CLEANCOMMAND:=find -maxdepth 1 -mindepth 1 ! -name Makefile ! -name .rsync-rules -exec rm -R {} \;

# MK command
MKCOMMAND:=cd ..;mkapp -t $(TARGET) -o Target_Legato_Debug -w Target_Legato_Debug -i "$(LEGATO_ROOT)/interfaces/wifi" -i "$(LEGATO_ROOT)/interfaces/airVantage" -i "$(LEGATO_ROOT)/interfaces/portService" -i "$(LEGATO_ROOT)/interfaces/logDaemon" -i "$(LEGATO_ROOT)/interfaces" -i "$(LEGATO_ROOT)/interfaces/watchdog" -i "$(LEGATO_ROOT)/interfaces/airVantage/legacy" -i "$(LEGATO_ROOT)/interfaces/positioning" -i "$(LEGATO_ROOT)/interfaces/atServices" -i "$(LEGATO_ROOT)/interfaces/secureStorage" -i "$(LEGATO_ROOT)/interfaces/modemServices" -i "$(LEGATO_ROOT)/interfaces/supervisor" -s "$(LEGATO_ROOT)/components/dataConnectionService/platformAdaptor/default" -s "$(LEGATO_ROOT)/apps/platformServices/airVantageConnector" -s "$(LEGATO_ROOT)/components/airVantage" -s "$(LEGATO_ROOT)/modules/WiFi/apps/tools/wifi" -s "$(LEGATO_ROOT)/components/positioning" -s "$(LEGATO_ROOT)/components/secStore" -s "$(LEGATO_ROOT)/components/portService" -s "$(LEGATO_ROOT)/components/uartMode/platformAdaptor/default" -s "$(LEGATO_ROOT)/components/modemServices/platformAdaptor/default" -s "$(LEGATO_ROOT)/components/audio/platformAdaptor/default" -s "." -s "$(LEGATO_ROOT)/components/3rdParty" -s "$(LEGATO_ROOT)/apps/tools" -s "$(LEGATO_ROOT)/components/fwupdate/platformAdaptor/default" -s "$(LEGATO_ROOT)/modules/WiFi/service" -s "$(LEGATO_ROOT)/components/dataConnectionService" -s "$(LEGATO_ROOT)/components/airVantage/platformAdaptor/default" -s "$(LEGATO_ROOT)/components/fwupdate" -s "$(LEGATO_ROOT)/components/positioning/platformAdaptor/default" -s "$(LEGATO_ROOT)/components/devMode" -s "$(LEGATO_ROOT)/components/secStore/platformAdaptor/default" -s "$(LEGATO_ROOT)/components/atServices" -s "$(LEGATO_ROOT)/components/modemServices" -s "$(LEGATO_ROOT)/components" -s "$(LEGATO_ROOT)/components/uartMode" -C -g -X -g -L -g testsql.adef -i $(CURDIR)/../third-party/inc \-L $(CURDIR)/../third-party/lib/libsqlite3.so \

# Custom makefile include: definitions
-include ../customDefs.mk

.PHONY: all target clean codegen mkCodegen airvantage

all: target

codegen: mkCodegen

mkCodegen:
	$(MKCOMMAND) --generate-code

target:
	$(MKCOMMAND)

clean:
	$(CLEANCOMMAND)

# Custom makefile include: targets
-include ../customTargets.mk

```

[Next page](https://forum.legato.io/t/undefined-reference-when-using-mksys-but-not-mkapp/6550.md?page=2)
