I am able to compile the code but when it is linking-time something does not work as expected.
I investigated a bit, and the problem is that the objects files used by the linker are ’empty’.
Likely, the build process is considering only the headers file and nothing else, but I have not idea how to fix it.
To replicate the problem just do as follow:
pi@raspberrypi:~/pico $ git clone [email protected]:ozw1z5rd/PicoMite.git -b hcg20-WIFI PicoMiteHCG20-WIFI
Cloning into 'PicoMiteHCG20-WIFI'...
remote: Enumerating objects: 3480, done.
remote: Counting objects: 100% (217/217), done.
remote: Compressing objects: 100% (153/153), done.
remote: Total 3480 (delta 121), reused 130 (delta 64), pack-reused 3263 (from 1)
Receiving objects: 100% (3480/3480), 8.19 MiB | 976.00 KiB/s, done.
Resolving deltas: 100% (2235/2235), done.
pi@raspberrypi:~/pico $ cd PicoMiteHCG20-WIFI/
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI $ git branch
* hcg20-WIFI
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI $ mkdir build
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI $ cd build/
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI/build $ cmake ..
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI/build $ make -j4
Scanning dependencies of target bs2_default
:
100%] Linking CXX executable PicoMiteWeb.elf
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/PicoMiteWeb.dir/PicoMite.c.obj: in function `routinechecks':
PicoMite.c:(.time_critical.routinechecks+0x4c): undefined reference to `tud_cdc_n_connected'
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: PicoMite.c:(.time_critical.routinechecks+0x8e): undefined reference to `tud_cdc_n_read'
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/PicoMiteWeb.dir/PicoMite.c.obj: in function `SerialConsolePutC':
PicoMite.c:(.text.SerialConsolePutC+0xd6): undefined reference to `tud_cdc_n_connected'
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/PicoMiteWeb.dir/PicoMite.c.obj: in function `main':
PicoMite.c:(.text.startup.main+0x350): undefined reference to `tud_cdc_n_connected'
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: PicoMite.c:(.text.startup.main+0x3bc): undefined reference to `stdio_usb'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/PicoMiteWeb.dir/build.make:3331: PicoMiteWeb.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1913: CMakeFiles/PicoMiteWeb.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
You can verify that into the build folder some of the object files produced actually are “empty”. Thus, the linker does not find the required symbols and fails.
For example, it it look at the cdc_device.c.obj used:
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI/build $ ls -l CMakeFiles/PicoMiteWeb.dir/home/pi/pico/pico-sdk/lib/tinyusb/src/class/cdc
total 4
-rw-r--r-- 1 pi pi 740 Aug 18 18:34 cdc_device.c.obj
It is just 704 bytes instead of 7184
The file has no symbols:
pi@raspberrypi:~/pico/PicoMiteHCG20-WIFI/build $ objdump -t CMakeFiles/PicoMiteWeb.dir/home/pi/pico/pico-sdk/lib/tinyusb/src/class/cdc/cdc_device.c.obj
CMakeFiles/PicoMiteWeb.dir/home/pi/pico/pico-sdk/lib/tinyusb/src/class/cdc/cdc_device.c.obj: file format elf32-littlearm
SYMBOL TABLE:
00000000 l df *ABS* 00000000 cdc_device.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .comment 00000000 .comment
00000000 l d .ARM.attributes 00000000 .ARM.attributes
It should be:
cdc_device.c.obj: file format elf32-littlearm
SYMBOL TABLE:
00000000 l df *ABS* 00000000 cdc_device.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .text._prep_out_transaction 00000000 .text._prep_out_transaction
00000000 l F .text._prep_out_transaction 00000048 _prep_out_transaction
00000000 l d .text.tud_cdc_n_connected 00000000 .text.tud_cdc_n_connected
00000000 l O .bss._cdcd_itf 000002c8 _cdcd_itf
00000000 l d .text.tud_cdc_n_get_line_state 00000000 .text.tud_cdc_n_get_line_state
00000000 l d .text.tud_cdc_n_get_line_coding 00000000 .text.tud_cdc_n_get_line_coding
00000000 l d .text.tud_cdc_n_set_wanted_char 00000000 .text.tud_cdc_n_set_wanted_char
00000000 l d .text.tud_cdc_n_available 00000000 .text.tud_cdc_n_available
00000000 l d .text.tud_cdc_n_read 00000000 .text.tud_cdc_n_read
00000000 l d .text.tud_cdc_n_peek 00000000 .text.tud_cdc_n_peek
00000000 l d .text.tud_cdc_n_read_flush 00000000 .text.tud_cdc_n_read_flush
00000000 l d .text.tud_cdc_n_write_flush 00000000 .text.tud_cdc_n_write_flush
00000000 l d .text.tud_cdc_n_write 00000000 .text.tud_cdc_n_write
00000000 l d .text.tud_cdc_n_write_available 00000000 .text.tud_cdc_n_write_available
00000000 l d .text.tud_cdc_n_write_clear 00000000 .text.tud_cdc_n_write_clear
00000000 l d .text.cdcd_init 00000000 .text.cdcd_init
00000000 l d .text.cdcd_reset 00000000 .text.cdcd_reset
00000000 l d .text.cdcd_open 00000000 .text.cdcd_open
00000000 l d .text.cdcd_control_xfer_cb 00000000 .text.cdcd_control_xfer_cb
00000000 l d .text.cdcd_xfer_cb 00000000 .text.cdcd_xfer_cb
00000000 l d .bss._cdcd_itf 00000000 .bss._cdcd_itf
00000000 l d .comment 00000000 .comment
00000000 l d .ARM.attributes 00000000 .ARM.attributes
00000000 *UND* 00000000 tu_fifo_remaining
00000000 *UND* 00000000 usbd_edpt_claim
00000000 *UND* 00000000 usbd_edpt_xfer
00000000 *UND* 00000000 usbd_edpt_release
00000000 g F .text.tud_cdc_n_connected 00000030 tud_cdc_n_connected
00000000 *UND* 00000000 tud_mounted
00000000 *UND* 00000000 tud_suspended
00000000 g F .text.tud_cdc_n_get_line_state 00000014 tud_cdc_n_get_line_state
00000000 g F .text.tud_cdc_n_get_line_coding 00000020 tud_cdc_n_get_line_coding
00000000 *UND* 00000000 memcpy
00000000 g F .text.tud_cdc_n_set_wanted_char 00000014 tud_cdc_n_set_wanted_char
00000000 g F .text.tud_cdc_n_available 00000018 tud_cdc_n_available
00000000 *UND* 00000000 tu_fifo_count
00000000 g F .text.tud_cdc_n_read 00000028 tud_cdc_n_read
00000000 *UND* 00000000 tu_fifo_read_n
00000000 g F .text.tud_cdc_n_peek 00000018 tud_cdc_n_peek
00000000 *UND* 00000000 tu_fifo_peek
00000000 g F .text.tud_cdc_n_read_flush 00000020 tud_cdc_n_read_flush
00000000 *UND* 00000000 tu_fifo_clear
00000000 g F .text.tud_cdc_n_write_flush 00000078 tud_cdc_n_write_flush
00000000 g F .text.tud_cdc_n_write 00000034 tud_cdc_n_write
00000000 *UND* 00000000 tu_fifo_write_n
00000000 g F .text.tud_cdc_n_write_available 00000018 tud_cdc_n_write_available
00000000 g F .text.tud_cdc_n_write_clear 00000018 tud_cdc_n_write_clear
00000000 g F .text.cdcd_init 0000007c cdcd_init
00000000 *UND* 00000000 memset
00000000 *UND* 00000000 tu_fifo_config
00000000 *UND* 00000000 mutex_init
00000000 g F .text.cdcd_reset 0000002c cdcd_reset
00000000 *UND* 00000000 tu_fifo_set_overwritable
00000000 g F .text.cdcd_open 000000b4 cdcd_open
00000000 *UND* 00000000 usbd_edpt_open
00000000 *UND* 00000000 usbd_open_edpt_pair
00000000 g F .text.cdcd_control_xfer_cb 000000dc cdcd_control_xfer_cb
00000000 w *UND* 00000000 tud_cdc_line_coding_cb
00000000 w *UND* 00000000 tud_cdc_line_state_cb
00000000 *UND* 00000000 tud_control_xfer
00000000 w *UND* 00000000 tud_cdc_send_break_cb
00000000 *UND* 00000000 tud_control_status
00000000 g F .text.cdcd_xfer_cb 00000104 cdcd_xfer_cb
00000000 *UND* 00000000 tu_fifo_empty
00000000 w *UND* 00000000 tud_cdc_rx_wanted_cb
00000000 w *UND* 00000000 tud_cdc_tx_complete_cb
00000000 w *UND* 00000000 tud_cdc_rx_cb
Of course, I can get the final binary by replacing the content of the build folder with the correctly compiled version from another project. In this case, I have to start the linker manually. Fortunately, it is possible to get the command line to be used from the output of make -j4 --trace
How can I fix the CMakeFiles.txt file to avoid the empty files?