Can't CC a makefile (C) for IMX6ULL

Hey! I’m having a problem with cross-compiling since few days and i can’t make it work.
I was using CC following this guide Configure Toolchain - Colibri iMX6 ULL
quite well, but now i needed to compile a .c program with a library (JSON-C library).
Thing is using recipe the program compiles and works good, but im doing changes to that program and flashing the imx6ull takes some time so i wanted to use a makefile.
This makefile compiles correctly in my ubuntu, but when i try to do it using cross compile it throws a lot of errors. I’ve tried changing the cross-compiler in the recipe and libraries but it doesn’t work.
Im using the IMX6ULL on a custom board, running core image minimal 5.7.2-devel-20230726155409+build.0

This is the make file im using:
TARGET = cabecera2

OBJS = cabecera.o tea.o Crc32.o

CFLAGS = -Wall

CC = /home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/arm-tdx-linux-gnueabi-gcc

LIBJSON_C_PATH = /home/yocto-project/oe-core/build/tmp/sysroots-components/armv7at2hf-neon/json-c/usr

OTRA_LIBRERIA_PATH = /home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/core-image-minimal/1.0-r0/recipe-sysroot/usr

OTRA_LIBRERIA_PATH2 = /usr/arm-linux-gnueabi

CFLAGS += -I$(LIBJSON_C_PATH)/include -I$(OTRA_LIBRERIA_PATH)/include -I$(OTRA_LIBRERIA_PATH2)/include

LDFLAGS += -L$(LIBJSON_C_PATH)/lib

$(TARGET) : $(OBJS)

@touch temEncriptado 00009999 tmp logs.dat post_tmp temDencriptado llegada 0024.inf 0025.inf 00699999.inf 0022.inf

#@echo “HOLAnda” >> logs.dat

$(CC) $(CFLAGS) $(OBJS) -ljson-c -o $(TARGET) $(LDFLAGS)

%.o : %.c

$(CC) -c $(CFLAGS) $< -o $@

-include *.d

.PHONY: clean

clean :

@rm -f *.o $(TARGET) temEncriptado 00009999 tmp logs.dat post_tmp temDencriptado llegada 0024.inf 0025.inf 00699999.inf 0022.inf

And the errors im getting:
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/arm-tdx-linux-gnueabi-gcc -Wall -I/home/yocto-project/oe-core/build/tmp/sysroots-components/armv7at2hf-neon/json-c/usr/include -I/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/core-image-minimal/1.0-r0/recipe-sysroot/usr/include -I/usr/arm-linux-gnueabi/include cabecera.o tea.o Crc32.o -ljson-c -o cabecera2 -Wl,-O1 -Wl,–hash-style=gnu -Wl,–as-needed -L/home/yocto-project/oe-core/build/tmp/sysroots-components/armv7at2hf-neon/json-c/usr/lib
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find Scrt1.o: No such file or directory
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find crti.o: No such file or directory
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find crtbeginS.o: No such file or directory
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find -lgcc
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find -lgcc_s
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find -lc
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find -lgcc
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find -lgcc_s
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find crtendS.o: No such file or directory
/home/yocto-project/oe-core/build/tmp/work/colibri_imx6ull-tdx-linux-gnueabi/linux-toradex/5.4.193+gitAUTOINC+b60d3160fd-r0/recipe-sysroot-native/usr/bin/arm-tdx-linux-gnueabi/…/…/libexec/arm-tdx-linux-gnueabi/gcc/arm-tdx-linux-gnueabi/9.5.0/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:21: cabecera2] Error 1

Sorry for long post, i’ll appreciate some help!

Did you actually install the toolchain and source the environment script? You really shouldn’t need to do all of that in the Makefile. You’re probably overwriting some of the vars that would normally be set up using the script.

You have to source that script in every shell you start.

You are saying that i should be able to compile just using a single line command with "${CC} -Wall … ? I installed toolchain and i’ve using it without problems so far but the thing is now i needed to compile few .c programs and tought maybe a makefile was the best option. Is there any other way?

Ok i tried not using the makefile and it compiled, but the program doesn’t run well. I’ve included all libraries that are necessary but at some point the program throws this error:
[ 2151.538687] 8<— cut here —
[ 2151.570759] cabecera2: unhandled page fault (11) at 0x2e393331, code 0x005
[ 2151.606705] pgd = 80c54b56
[ 2151.638815] [2e393331] *pgd=00000000
[ 2151.671488] CPU: 0 PID: 460 Comm: cabecera2 Not tainted 5.4.193-5.7.2-devel+g it.b60d3160fd04 #1
[ 2151.739742] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[ 2151.776176] PC is at 0x76f12b92
[ 2151.809344] LR is at 0x76f1279f
[ 2151.841451] pc : [<76f12b92>] lr : [<76f1279f>] psr: 200f0030
[ 2151.876525] sp : 7e921a88 ip : 7e921b6a fp : 00000000
[ 2151.910340] r10: 76feefa4 r9 : 00000000 r8 : 00000000
[ 2151.943798] r7 : 7e921a98 r6 : 00000000 r5 : 2e393331 r4 : 7e921b14
[ 2151.977858] r3 : 0000000f r2 : 00000010 r1 : 2e393331 r0 : 7e921b6a
[ 2152.011143] Flags: nzCv IRQs on FIQs on Mode USER_32 ISA Thumb Segment u ser
[ 2152.071205] Control: 10c5387d Table: 94b1806a DAC: 00000055
[ 2152.103341] CPU: 0 PID: 460 Comm: cabecera2 Not tainted 5.4.193-5.7.2-devel+g it.b60d3160fd04 #1
[ 2152.164212] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[ 2152.196517] [<8010ec98>] (unwind_backtrace) from [<8010bc04>] (show_stack+0x1 0/0x14)
[ 2152.255534] [<8010bc04>] (show_stack) from [<809180e8>] (dump_stack+0x90/0xa4 )
[ 2152.314698] [<809180e8>] (dump_stack) from [<80112e24>] (__do_user_fault+0xfc /0x100)
[ 2152.375204] [<80112e24>] (__do_user_fault) from [<80113204>] (do_page_fault+0 x354/0x394)
[ 2152.437068] [<80113204>] (do_page_fault) from [<801133ac>] (do_DataAbort+0x3c /0xc0)
[ 2152.498524] [<801133ac>] (do_DataAbort) from [<80101e3c>] (__dabt_usr+0x3c/0x 40)
[ 2152.560444] Exception stack(0x94f11fb0 to 0x94f11ff8)
[ 2152.593352] 1fa0: 7e921b6a 2e393331 00000 010 0000000f
[ 2152.656493] 1fc0: 7e921b14 2e393331 00000000 7e921a98 00000000 00000000 76fee fa4 00000000
[ 2152.719628] 1fe0: 7e921b6a 7e921a88 76f1279f 76f12b92 200f0030 ffffffff

Any idea what could be happenning? Clearly this doesn’t happen when i compile the exact same program with the recipe.

Well, you could do it with a single command. But using a Makefile would be the right way to go if you don’t want to do recipes and stuff.

If you followed those instructions in the link you posted originally, you’d have the toolchain installed somewhere. At that point, you don’t need to modify CC inside of your Makefile IF you ran the env setup script like the doc said:

. /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi (example)

That script would set up the environment variables for you. Type an echo($CC) on the command line to see if that’s populated. You could also do “env” and see all of the fun stuff defined by that setup script.

Seems like your Makefile can’t find the libraries and standard sysroot stuff, so I think the redefinition of the CC is messing you up?

No, as i posted i was able to correctly compile the program and it’s libraries using command ${CC} and the program runs for a bit, until it reaches a point where specifically opens a http socket and sends data, then the program stops and shows the error just how i showed in the last reply. I don’t know why it behaves like this given that running the same program but compiled in the recipe works just fine.
Ty for your help

My last reply had crossed with yours (I never saw your other one). I wouldn’t abandon the Makefile, but at least you’re compiling now. You’re in the “how do I debug it” mode. Either start pulling out code or figure out how to run gdb with symbols to see where things go haywire.

It’s going to be really hard to reproduce your setup and help you out, maybe my other colleagues can chip in and see something that I’m not.

I wouldn’t abandon the Makefile, but at least you’re compiling now.

Agreed. Page faults are generally result of your executable trying to access some address that it shouldn’t, so maybe something has gone wrong in the linking process. You can use something like objdump to analyze the contents of both binaries, which may help to diagnose to issue.

Thank you both for your replies, i’ll definetely try those approaches.