Hello all,
I am trying to merge two codes (app_main.cpp and main.c) and my folder structure looks like this
Project
#->Cmakelists.txt
#->Makefile
#->sdkconfig
#->Main
### ->Cmakelists.txt
### ->main.c
### ->main.h (I added this)
### ->app_main.cpp
Both main.c and app_main.cpp have "void app_main()"
So my approach was to change "app_main()" to "c_app_main()" in main.c and also removed while(1) since I have it in app_main.cpp. I also added "main.h" and declared "c_app_main()".
I updated the Cmakelists.txt to compile both app_main.cpp and main.c
Now I am getting this error
````
/home/linux/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal._Z8run_demov+0x14): undefined reference to `c_app_main()'
/home/linux/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/main/libmain.a(app_main.cpp.obj): in function `run_demo()':
/home/linux/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.4.0/bits/stl_vector.h:567: undefined reference to `c_app_main()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/app-template.elf.dir/build.make:508: app-template.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1767: CMakeFiles/app-template.elf.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
make failed with exit code 2
````
Can someone suggest what to do, It would be of great help
Thanks in advance
How do I merge 2 codes with "app_main" and one .c and other .cpp
Re: How do I merge 2 codes with "app_main" and one .c and other .cpp
Also remember that you can have just 1 app_main() function, which is the main entry function for your application.
So just updating CMakeLists.txt is not enough, you need to merge the code if multiple app_main() functions exist.
So just updating CMakeLists.txt is not enough, you need to merge the code if multiple app_main() functions exist.
Re: How do I merge 2 codes with "app_main" and one .c and other .cpp
Thanks a lot for the replies, I was able to make it up and running.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 115 guests