[IDFGH-2941] ELF file is in wrong place after running cmake --build .
Posted: Thu Mar 19, 2020 5:32 am
I am using the idf as a lib in my cmake project (idf.cmake). It seems the majority of the build runs through, but during the end of `cmake --build .` I get an error my ELF cannot be found, even when it exists down build/main/MYPROJECT.ELF. It appears either my ELF is in the wrong place or what generates the build/main/CMakeFiles/gen_project_binary.dir/build.make is incorrect.
build/main/CMakeFiles/gen_project_binary.dir/build.make looks like this originally
but when I change the MYPROJECT.ELF to main/MYPROJECT.ELF at the end of the python call, as below, and run `cmake --build .` it works correctly
My file structure is:
- components/
--comp1/
---CMakeLisst.txt
---comp1_main.c
-main/
--CMakeLists.txt
--main.c
-build/
sdkconfig
CMakeLists.txt
the top level cmake is simple
CMakeLists.txt:
The Cmake nested in main is
main/CMakeLists.txt:
to build I run this in the build directory:
Also my build directory looks like this, note the MYPROJECT.elf at in the main/ dir, not in the top level build dir
Why might the build.make be incorrectly generated or my ELF placed in the wrong place?
TIA
Code: Select all
[100%] Generating binary image from built executable
esptool.py v2.8
Traceback (most recent call last):
File "/home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 3201, in <module>
_main()
File "/home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 3194, in _main
main()
File "/home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2965, in main
operation_func(args)
File "/home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2466, in elf2image
e = ELFFile(args.input)
File "/home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 1951, in __init__
with open(self.name, 'rb') as f:
[b]IOError: [Errno 2] No such file or directory: 'MYPROJECT.elf'
[/b]main/CMakeFiles/gen_project_binary.dir/build.make:60: recipe for target '.bin_timestamp' failed
make[2]: *** [.bin_timestamp] Error 1
CMakeFiles/Makefile2:99: recipe for target 'main/CMakeFiles/gen_project_binary.dir/all' failed
make[1]: *** [main/CMakeFiles/gen_project_binary.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Code: Select all
.bin_timestamp: main/MYPROJECT.elf
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/home/myuser/work/MYPROJECT/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating binary image from built executable"
[b] python /home/myuser/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 2MB --elf-sha256-offset 0xb0 -o /home/myuser/work/MYPROJECT/build/MYPROJECT.bin MYPROJECT.elf
[/b] /usr/bin/cmake -E echo "Generated /home/myuser/work/MYPROJECT/build/MYPROJECT.bin"
/usr/bin/cmake -E md5sum /home/myuser/work/MYPROJECT/build/MYPROJECT.bin > /home/myuser/work/MYPROJECT/build/.bin_timestamp
Code: Select all
python /home/scarlson/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 2MB --elf-sha256-offset 0xb0 -o /home/scarlson/work/SimPill/build/SIMPILL.bin main/SIMPILL.elf
My file structure is:
- components/
--comp1/
---CMakeLisst.txt
---comp1_main.c
-main/
--CMakeLists.txt
--main.c
-build/
sdkconfig
CMakeLists.txt
the top level cmake is simple
CMakeLists.txt:
Code: Select all
cmake_minimum_required(VERSION 3.5)
project(MYPROJECT C)
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
set(INCLUDE_DIRS ${CMAKE_HOME_DIRECTORY}/include)
# You could in theory have more than one subdirectory for
# piecemeal builds
add_subdirectory(main)
main/CMakeLists.txt:
Code: Select all
cmake_minimum_required(VERSION 3.5)
set(SUPPORTED_TARGETS esp32)
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
idf_build_component(${CMAKE_HOME_DIRECTORY}/components/comp1)
idf_build_process(esp32
COMPONENTS esp32 freertos esptool_py comp1
SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig
BUILD_DIR ${CMAKE_BINARY_DIR})
add_executable(${elf_file} main.c)
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash)
idf_build_executable(${elf_file})
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
Code: Select all
cmake .. -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32 -G 'Unix Makefiles'
cmake --build .
Code: Select all
myuser@ubuntu:~/work/MYPROJECT/build$ ls main/
bootloader-prefix CMakeFiles cmake_install.cmake config.env Makefile mconf-idf-prefix MYPROJECT.elf
myuser@ubuntu:~/work/MYPROJECT/build$ ls
bootloader CMakeFiles compile_commands.json esp-idf flash_bootloader_args flash_partition_table_args kconfig_bin ldgen_libraries.in Makefile sdkconfig
CMakeCache.txt cmake_install.cmake config flash_app_args flasher_args.json flash_project_args ldgen_libraries main partition_table
TIA