Undefined reference when using mksys, but not mkapp

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?

how about embed the application to legato.cwe?

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.

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?

	[r] third-party/lib/libsqlite3.so /lib/



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

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

		${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:

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

MKSYS_ARGS_COMMON = -s $(WORKSPACE_ROOT)/apps/GpioExpander/gpioExpanderService
MKSYS_ARGS_NEURON_MQTT = -s $(WORKSPACE_ROOT)/apps/neuron_iotgw/

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

.PHONY: 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 \

.PHONY: 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 \
`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

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

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

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

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

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

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

/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.

/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

Of course you need to install toolchain …

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

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.

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

Did you modify the makefile

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

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

		${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

Then why it cannot find the compiler?

Weird, I am using the vscode plugin.

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

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

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

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:



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

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

# Define target type

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

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

# Target artifact.*

# 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

	$(MKCOMMAND) --generate-code



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