最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cmake - Trouble adding files to CMakeLists.txt - Stack Overflow

programmeradmin3浏览0评论

I am working on an ESP32 project and for reference I've installed the ESP-IDF plugin for VSCode (running on Win11, btw) and I'm on IDF v5.4.0 running on an ESP32-S3. I created a new project and used blinky as the template. (FWIW I'm running a Waveshare module with GPS and 5G modem but haven't gotten that far.)

I took the basic blinky (which worked) and put the code in its own thread alongside a main thread. This all works as expected. I need to add some additional source files to the build. As a test case, I created a file called ResourceFunctions.c and placed it in the main folder. in this file I created one function:

#include <stdint.h>

uint16_t AddThree(uint16_t _input)
{
    return _input + 3;
}

and prototyped it in the main code file. This new file, and the main file, and CMakeLists.txt are all in the same "main" folder.

CMakeLists..txt looks like this:

idf_component_register(SRCS "blink_example_main.c"
       INCLUDE_DIRS  ".")

I changed CMakeLists.txt per things I found here and other places on the web (add the new source file name to the list after SRCS) to look like this:

idf_component_register(SRCS "blink_example_main.c" "ResourceFunctions.c"
       INCLUDE_DIRS  ".")

and made a simple call to it from the blinky thread (the variable was declared above the function call):

counter = AddThree(counter);

I get the following error:

CMake Error at C:/ESP/Frameworks/v5.4/esp-idf/tools/cmake/component.cmake:490 (add_library):
  Cannot find source file:

    C:/ESP/Projects/T_Monitor/main/ResourceFunctions.c

  Tried extensions .c .C .c++  .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  m .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  main/CMakeLists.txt:1 (idf_component_register)


CMake Error at C:/ESP/Frameworks/v5.4/esp-idf/tools/cmake/component.cmake:490 (add_library):
  No SOURCES given to target: __idf_main
Call Stack (most recent call first):
  main/CMakeLists.txt:1 (idf_component_register)


CMake Generate step failed.  Build files cannot be regenerated correctly.
ninja: error: rebuilding 'build.ninja': subcommand failed

FAILED: build.ninja
C:\ESP\Tools\tools\cmake\3.30.2\bin\cmake.exe --regenerate-during-build -SC:\ESP\Projects\T_Monitor -BC:\ESP\Projects\T_Monitor\build

 *  The terminal process "c:\ESP\Tools\tools\ninja\1.12.1\ninja.exe" terminated with exit code: 1. 

I even tried an "alternate format" I found (which tbh, I like better because each source file is on its own line):

df_component_register(SRCS 
    "blink_example_main.c" 
    "ResourceFunctions.c"
INCLUDE_DIRS 
    "."
)

resulting in the same error.

Someone suggested I delete the build folder and let it regen (I had already tried "clean" a bunch of times, btw) and then got this error:

CMake Error at C:/ESP/Frameworks/v5.4/esp-idf/tools/cmake/component.cmake:490 (add_library):
  Cannot find source file:

    C:/ESP/Projects/T_Monitor/main/ResourceFunctions.c

  Tried extensions .c .C .c++  .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  m .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  main/CMakeLists.txt:1 (idf_component_register)


CMake Error at C:/ESP/Frameworks/v5.4/esp-idf/tools/cmake/component.cmake:490 (add_library):
  No SOURCES given to target: __idf_main
Call Stack (most recent call first):
  main/CMakeLists.txt:1 (idf_component_register)


CMake Generate step failed.  Build files cannot be regenerated correctly.

 *  The terminal process "c:\ESP\Tools\tools\cmake\3.30.2\bin\cmake.exe '-G', 'Ninja', '-DPYTHON_DEPS_CHECKED=1', '-DESP_PLATFORM=1', '-B', 'c:\ESP\Projects\T_Monitor\build', '-S', 'c:\ESP\Projects\T_Monitor', '-DSDKCONFIG=c:\ESP\Projects\T_Monitor\sdkconfig'" terminated with exit code: 1. 

 *  Executing task: c:\ESP\Tools\tools\ninja\1.12.1\ninja.exe  

ninja: error: loading 'build.ninja': The system cannot find the file specified.


 *  The terminal process "c:\ESP\Tools\tools\ninja\1.12.1\ninja.exe" terminated with exit code: 1. 

 *  Executing task: c:\ESP\Tools\tools\ninja\1.12.1\ninja.exe  

ninja: error: loading 'build.ninja': The system cannot find the file specified.


 *  The terminal process "c:\ESP\Tools\tools\ninja\1.12.1\ninja.exe" terminated with exit code: 1. 

(I also got a weird error one time saying it couldn't find some fin in the IDF itself.)

As a sanity check (to make sure I had done nothing to the project/tools as a whole) I removed all references to the new file and function and rebuilt (no clean or anything) and it built and ran just fine.

Here are the contents of the main folder:


03/31/2025  05:18 PM    <DIR>          .
03/31/2025  05:17 PM    <DIR>          ..
03/31/2025  12:46 PM             4,263 blink_example_main.c
03/31/2025  12:46 PM               133 CMakeLists.txt
03/13/2025  02:26 PM                48 idf_component.yml
03/13/2025  02:26 PM             1,620 Kconfig.projbuild
03/31/2025  12:27 PM                89 ResourceFunctions.c

Any thoughts would be appreciated.

发布评论

评论列表(0)

  1. 暂无评论