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
There's something I'm missing: Eclipse C++ and ESP32
Re: There's something I'm missing: Eclipse C++ and ESP32
Howdy,
Have a good read at the following:
http://esp-idf.readthedocs.io/en/latest ... -makefiles
At the highest level, create an ESP32 project (eg. one that contains main). In the project root, create a folder called components. In the components folder, create a new folder for EACH component you want to create. For any given component, go into the directory of that component and create the source files, header files AND a component.mk file.
Have a good read at the following:
http://esp-idf.readthedocs.io/en/latest ... -makefiles
At the highest level, create an ESP32 project (eg. one that contains main). In the project root, create a folder called components. In the components folder, create a new folder for EACH component you want to create. For any given component, go into the directory of that component and create the source files, header files AND a component.mk file.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: There's something I'm missing: Eclipse C++ and ESP32
Kolban,
Thanks for the insight; it compiles.
But I'm still confused and the doc linked had a vocabulary that included too many unknowns for me at my current level; hopefully, my knowledge will grow to the point where I can say: "of course."
Meanwhile, if you don't mind, I've got a couple of questions regarding this.
1. I copied the component.mk file into the 'components' folder. When I saved it, I ended up with two 'components' directories shown in the Project Explorer. In a terminal at top level of all the projects, I did (I'm on Ubuntu 17.10) a "find . -name MyClass.cpp, and there was only one found. So, not sure why I had two directories both named 'components' in the same project. "ll" for the root of the project only showed one directory existed, and it contained the "comonents.mk" file in it; only one of the two in the Project Explorer had the components.mk file. I restarted Eclipse, and it went back to a single 'component' directory.....I did notice when there were two in existance that one had a tiny 'c' on it's folder icon, while the other folder had no icon.
2. The doc link is talking about components, which I take to means something like a DHT22, but I don't have any 'real components' at this time, just a Class. So I'm assuming a Class is a component in this vernacular? I haven't come across anything in the documentation that refers to this.
3. Most of the examples I've been able to look at are derived using Arduino Core, and are C programs. Searching github for esp32 and C++, I find some but typically they are either too large and I get lost, or they are too simple and don't shed any light on this. Do you have a concise example in your published code somewhere that I can dig into that would, in some form, provide insight into the use of multiple classes as might be used in a project that makes use of polymorphism or inheritance?
4. <added via edit to original> Was I correct that I have to add the directory location where the cpp and h files are located to the 'include' of the 'paths and symbols'?
Thanks so much for your time on this. There just doesn't appear to be a lot available yet that I've been able to find via google, whether text based or youtube based, so your comment above is the first thing that's shed a little light on this for me!
JavaBen
Thanks for the insight; it compiles.
But I'm still confused and the doc linked had a vocabulary that included too many unknowns for me at my current level; hopefully, my knowledge will grow to the point where I can say: "of course."
Meanwhile, if you don't mind, I've got a couple of questions regarding this.
1. I copied the component.mk file into the 'components' folder. When I saved it, I ended up with two 'components' directories shown in the Project Explorer. In a terminal at top level of all the projects, I did (I'm on Ubuntu 17.10) a "find . -name MyClass.cpp, and there was only one found. So, not sure why I had two directories both named 'components' in the same project. "ll" for the root of the project only showed one directory existed, and it contained the "comonents.mk" file in it; only one of the two in the Project Explorer had the components.mk file. I restarted Eclipse, and it went back to a single 'component' directory.....I did notice when there were two in existance that one had a tiny 'c' on it's folder icon, while the other folder had no icon.
2. The doc link is talking about components, which I take to means something like a DHT22, but I don't have any 'real components' at this time, just a Class. So I'm assuming a Class is a component in this vernacular? I haven't come across anything in the documentation that refers to this.
3. Most of the examples I've been able to look at are derived using Arduino Core, and are C programs. Searching github for esp32 and C++, I find some but typically they are either too large and I get lost, or they are too simple and don't shed any light on this. Do you have a concise example in your published code somewhere that I can dig into that would, in some form, provide insight into the use of multiple classes as might be used in a project that makes use of polymorphism or inheritance?
4. <added via edit to original> Was I correct that I have to add the directory location where the cpp and h files are located to the 'include' of the 'paths and symbols'?
Thanks so much for your time on this. There just doesn't appear to be a lot available yet that I've been able to find via google, whether text based or youtube based, so your comment above is the first thing that's shed a little light on this for me!
JavaBen
Re: There's something I'm missing: Eclipse C++ and ESP32
Howdy,
I really do want to help but I think I would be having to talk pages and pages to get the story across. Maybe we can take it one small piece at a time and the dam will break.
The concept of a component in the ESP-IDF build system is a self contained "unit of function". Components are "directories" that contain everything they need to build and link. They exist in your projects "components" directory. When you want to add a component to your project, you need only source it and place it in the components directory, build and it will be there.
The ESP-IDF itself is made up of many components and you can create your own component. The purpose of creating a component is so that you will be able to "re-use" it in other projects. If you don't need to create a component ... then don't and just place the source files you want to compile in the main directory.
I really do want to help but I think I would be having to talk pages and pages to get the story across. Maybe we can take it one small piece at a time and the dam will break.
The concept of a component in the ESP-IDF build system is a self contained "unit of function". Components are "directories" that contain everything they need to build and link. They exist in your projects "components" directory. When you want to add a component to your project, you need only source it and place it in the components directory, build and it will be there.
The ESP-IDF itself is made up of many components and you can create your own component. The purpose of creating a component is so that you will be able to "re-use" it in other projects. If you don't need to create a component ... then don't and just place the source files you want to compile in the main directory.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: There's something I'm missing: Eclipse C++ and ESP32
OK, thanks.
Now that I can compile a sub-class via a components directory, I can move forward with building small examples and find my way out of the weeds.
Thanks again!
JavaBen
Now that I can compile a sub-class via a components directory, I can move forward with building small examples and find my way out of the weeds.
Thanks again!
JavaBen
Re: There's something I'm missing: Eclipse C++ and ESP32
Learned something today...
(ref: https://www.youtube.com/watch?v=-ttiPfmrehU)
If I don't do the step "Preprocessor Includes", "Providers" tab, "CDT GCC Built-in Compiler Settings":
- Change "${COMMAND}" to "xtensa-esp32-elf-gcc", then I will have errors flagged such as: Can't find file <iostream> in my header file where I'm trying to include it.
Examining the 'Includes' on Project Explorer (per the video above, I had included the c_include.xml file from 'esp-snippets'), I noted the reference (grayed out on my system because I installed local) to /opt/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0", because I did a local install to my home directory.
Changing the ${COMMAND} and Finish, will generate the correct link (on my system) of:
/home/<myhome>/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0.
which is otherwise missing.
(ref: https://www.youtube.com/watch?v=-ttiPfmrehU)
If I don't do the step "Preprocessor Includes", "Providers" tab, "CDT GCC Built-in Compiler Settings":
- Change "${COMMAND}" to "xtensa-esp32-elf-gcc", then I will have errors flagged such as: Can't find file <iostream> in my header file where I'm trying to include it.
Examining the 'Includes' on Project Explorer (per the video above, I had included the c_include.xml file from 'esp-snippets'), I noted the reference (grayed out on my system because I installed local) to /opt/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0", because I did a local install to my home directory.
Changing the ${COMMAND} and Finish, will generate the correct link (on my system) of:
/home/<myhome>/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0.
which is otherwise missing.
Re: There's something I'm missing: Eclipse C++ and ESP32
...and another thing
I also learned, if I want to 'include' code from another project (a UnitTest project of Assert classes and methods), when adding to the 'Paths and Symbols', I need to specify the 'filesystem', not the 'workspace'. Using 'workspace', my 'included' files weren't found; using 'filesystem', they were found and the errors went away on compile.
JB
I also learned, if I want to 'include' code from another project (a UnitTest project of Assert classes and methods), when adding to the 'Paths and Symbols', I need to specify the 'filesystem', not the 'workspace'. Using 'workspace', my 'included' files weren't found; using 'filesystem', they were found and the errors went away on compile.
JB
Re: There's something I'm missing: Eclipse C++ and ESP32
Well, I'm giving up on Eclipse for building my project; I'll continue to use it as an editor, at least for the time being.
So, this will be the last post regarding my getting started with using the Eclipse C++ ESP32 development. I think building manual make files will work better.
So, this will be the last post regarding my getting started with using the Eclipse C++ ESP32 development. I think building manual make files will work better.
Who is online
Users browsing this forum: axellin and 74 guests