There's something I'm missing: Eclipse C++ and ESP32
Posted: Mon Apr 02, 2018 11:40 pm
There's just something I'm missing that is causing me a lot of confusion.
I am familiar with coding classes and object for OOD, and am trying to implement this into a design I'm doing. But I can't get far enough with the Eclipse/ESP/C++ environment to get to design.
I'm using Kolban's youtube https://www.youtube.com/watch?v=-ttiPfmrehU as that's the approach that appears to be what I need.
I can get Kolban's example setup and main_helloworld.cpp to compile and run. In the example, the main(folder) contains helloworld.cpp.
I have a new class MyClass.cpp and MyClass.h. The class has one public method "sayHello()" which uses cout << to output "Hello".
If I place my MyClass.cpp and MyClass.h into the main(folder), modify the main_helloworld.cpp to #include "MyClass.h", then it works as expected; no problems compiling.
Here's my problem.
I want to put my code into a separate folder, e.g., components. So, I create a folder in my project named 'components' tat is at the same level as the main(folder). Then I move both MyClass.h and MyClass.cpp into the components(folder). Compiling gives an error, as expected by me, that it can't find MyClass.h.
So I modify the Properties/C++ General->Paths and Symbols, and click 'Add' button, and add the (Workspace button) 'components' directory. I do this 'add' via 'workspace' for all three languages: Assembly, C, and C++. Save and finish out.
So, since I just added the path, and not real clear on when things need to be done, I do the 'Index Rebuild', and 'Clean Project' and 'Build Project'.
And it fails to compile with the following errors <below>
In the main_helloworld.cpp, I've tried the following include statements:
#include "MyClass.h"
#include "../components/MyClass.h"
and I've tried with <> instead of ""; nothing works.
So some concept is eluding me and preventing me from moving forward with my efforts.
Thanks for any help offered!
<compile errors follow>
/home/superben/eclipse-workspace/ESP32/TestApr02/build/main/libmain.a(main_helloworld.o):(.literal.app_main+0xc): undefined reference to `MyClass::sayHello()'
/home/superben/esp/esp-idf/make/project.mk:388: recipe for target '/home/superben/eclipse-workspace/ESP32/TestApr02/build/app-template.elf' failed
/home/superben/eclipse-workspace/ESP32/TestApr02/build/main/libmain.a(main_helloworld.o): In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const':
/home/superben/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.h:135: undefined reference to `MyClass::sayHello()'
collect2: error: ld returned 1 exit status
make: *** [/home/superben/eclipse-workspace/ESP32/TestApr02/build/app-template.elf] Error 1
I am familiar with coding classes and object for OOD, and am trying to implement this into a design I'm doing. But I can't get far enough with the Eclipse/ESP/C++ environment to get to design.
I'm using Kolban's youtube https://www.youtube.com/watch?v=-ttiPfmrehU as that's the approach that appears to be what I need.
I can get Kolban's example setup and main_helloworld.cpp to compile and run. In the example, the main(folder) contains helloworld.cpp.
I have a new class MyClass.cpp and MyClass.h. The class has one public method "sayHello()" which uses cout << to output "Hello".
If I place my MyClass.cpp and MyClass.h into the main(folder), modify the main_helloworld.cpp to #include "MyClass.h", then it works as expected; no problems compiling.
Here's my problem.
I want to put my code into a separate folder, e.g., components. So, I create a folder in my project named 'components' tat is at the same level as the main(folder). Then I move both MyClass.h and MyClass.cpp into the components(folder). Compiling gives an error, as expected by me, that it can't find MyClass.h.
So I modify the Properties/C++ General->Paths and Symbols, and click 'Add' button, and add the (Workspace button) 'components' directory. I do this 'add' via 'workspace' for all three languages: Assembly, C, and C++. Save and finish out.
So, since I just added the path, and not real clear on when things need to be done, I do the 'Index Rebuild', and 'Clean Project' and 'Build Project'.
And it fails to compile with the following errors <below>
In the main_helloworld.cpp, I've tried the following include statements:
#include "MyClass.h"
#include "../components/MyClass.h"
and I've tried with <> instead of ""; nothing works.
So some concept is eluding me and preventing me from moving forward with my efforts.
Thanks for any help offered!
<compile errors follow>
/home/superben/eclipse-workspace/ESP32/TestApr02/build/main/libmain.a(main_helloworld.o):(.literal.app_main+0xc): undefined reference to `MyClass::sayHello()'
/home/superben/esp/esp-idf/make/project.mk:388: recipe for target '/home/superben/eclipse-workspace/ESP32/TestApr02/build/app-template.elf' failed
/home/superben/eclipse-workspace/ESP32/TestApr02/build/main/libmain.a(main_helloworld.o): In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const':
/home/superben/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.h:135: undefined reference to `MyClass::sayHello()'
collect2: error: ld returned 1 exit status
make: *** [/home/superben/eclipse-workspace/ESP32/TestApr02/build/app-template.elf] Error 1