I'm trying to compile an Arduino/C++ program for an ESP8266 and am running into a strange error that I cannot resolve. I am using MS Visual Studio Code, and even though I have the path to the header file for the Adafruit MQTT library in my includePath section of the c_cpp_properties.json file, when I try to compile the my source, I get the following in the output:
src\main.cpp:3:27: fatal error: Adafruit_MQTT.h: No such file or directory
#include "Adafruit_MQTT.h"
^ compilation terminated.
*** [.pioenvs\esp12e\src\main.o] Error 1
What's odd is that if I right-click on the include statement for the header, and click Goto Definition, the library code is indeed pulled up.
This makes me think that the IDE can find the file but the compiler cannot. Unfortunately I haven't used MS-VSC before so not sure why this might be happening.
Does anyone with more experience in this know where I should focus my attention?
Thanks for any and all help.
Does the program compile if you place the header file "Adafruit_MQTT.h" in the same directory as your main.cpp?
Using the quotes around the name of the header file makes the compiler look for the file in the same directory as the including file.
Related
I have a Qt project, accessing another cross-platform (boost) project on my disc. Adding the header includes does not seem to cause any problem.
#include "../../Visual Studio 2015/Projects/..." //Header file down the road
Adding existing source files to the sources folder in my Qt Project works also without a problem, the files are found and I can open them. I believe the files are not correctly compiled - if at all - as I get a linker error, telling me that %sourcefile%.obj could not be opened. (not created)
LNK1104: cannot open file 'debug\Error.obj'
I tried copying the content of Error.cpp into a new .cpp file created in the Qt project directory. After that the error message jumped to the next source file. I could now do this for all source files, but this seems to be quite... unhandy. Changes in the original project won't affect the Qt project then.
Does somebody know the problem / got a solution to it ?
I checked this question, answer and comments already, but that did not seem to fix the error or change anything.
The solution was quite simple and a little strange. It appears that something is causing an issue when using paths with spaces with Qt's include(...) and SOURCES in a *.pro file.
//This apparently works and source files are compiled.
include(C:/ProjDir/ProjName.pri)
//This works too, but the source files are not being compiled.
include("../../Visual Studio 2015/Projects/ProjDir/ProjName.pri")
Thanks to JKSH on the Qt-Forums and Sebastian for his hint using a .pri file.
I'm trying to create a new project with lpc11u68 MCU for USB HID application based on the LPCOPEN sample project.
The problem is, the compiler can't recognize header files on the other folder. It shows this
error:../Main/src/Main.cpp:12:26: fatal error: app_usbd_cfg.h: No such file or directory
I've exactly done all of the instructions in this tutorial but the problem is still alive. When I copy all header and sources to the main directory of the project, it compiled correctly!
I was using quick setting -> include path for introducing my header's path to the Xpresso. This acts just as the instruction described in above tutorial, but only in C projects!
When you used that shortcut in C++ project, it adds paths to the C compiler Includes not to the C++ one! What an interesting bug!
I am working in eclipse with MinGw (g++) compiler.
So my problem is when I import .h file from library I have downloaded and I try to build(compile) my project, error is "no such file or directory" for that .h file you can see on picture but still the class from that header file is recognised in the code!
Another strange thing is if I make intentional error in that .h file #import is succesfull and the error from that .h file is shown, that means it trys to compile that .h file.
So it does not know where the file is but it still compiles it ??? what???
cmd line:
g++ -Ic:D:\Documents\cpp_testing\bignum_testing\lib Main.cpp
error:
Main.cpp:10:22: fatal error: Cbignums.h: No such file or directory
#include "Cbignums.h"
^
compilation terminated.
I hope somone will know how to fix this and that it will help other people!
Picture without error in .h file:
Picture with intentional error in .h file!
I suspect that you should
#include "lib/Cbignums.h"
in bignum_testing.cpp if that is the path of the Cbignums.h - relative to the source file.
The IDE recognizes the type because you have the header in your project but the red lines indicate that the include will fail.
EOF is mostly a C thing from <cstdio> (or <stdio.h> form the C standard library, not the C++ one) which you probably forgot to include (e.g. by commenting its //#include <cstdio>)
Try compiling with appropriate -I and -H preprocessor options to g++ (of course, take time to read the documentation to find what they are doing).
BTW, you could ask for the preprocessed form with g++ -C -E Cbignums.cpp > Cbignums.ii then look, with some editor or pager, into the generated Cbignums.ii file.
I strongly recommend you to read a good book about Programming using C++ and to read the GCC documentation. In general, read the documentation of everything you are using for development (tools, e.g. compilers, and libraries)
PS. Every free software C++ compiler I know (GCC & Clang/LLVM...) are command line tools, so run them in a terminal, perhaps thru GNU make. Notice that Eclipse is not a compiler (it is an editor, self-glorified as an IDE), and you probably are not using it cleverly. Don't forget to pass -Wall -g to g++
I'm currently stuck on a compilation problem on Android for my app.
I get the following error during the compilation of my native library with ndk-build:
BackgroundDisplayConfiguration.h:12:23: fatal error: glm/glm.hpp:
No such file or directory
#include <glm/glm.hpp>
^
What puzzles me is that I have specified a path for this header only library in my Android.mk the following way:
LOCAL_CPPFLAGS += -I../../glm/include
and this path exists and is correct, but moreover if I mess up this path I get the same error in other files that include glm.hpp. When the path is correct, only this file yields an error, and I don't understand why. Any pointers?
EDIT: Okay, this is even more puzzling. The include option appear in every compiler command for each file, but not on the compiler command for the big wrapper generated by swig (that outputs my library_native_wrap.o), and that's where it yields an error... Well, it at least explains the observed behavior.
So I found a workaround for this, even though it doesn't feel quite right.
Indeed, I found out that when compiling every source of my library, the compiler command actually had the include option, but then, when compiling the output of swig (that big unique c++ wrapper file), the option wasn't there anymore.
I found a way to correct this by adding my include path to the LOCAL_EXPORT_C_INCLUDES.
For some reason, the LOCAL_CPPFLAGS aren't used when compiling the wrapper...
This consists of the declarations in my MainWindow file, I haven't included the library inclusions for brevity. I have included QObject.h in both, and all required libraries. It was compiling fine before the inclusion of the second connect call. The first Ctrl-C handler works fine.
I took out my code, thought my employer wouldn't like it. See the appropriate response below!
I am using QT Creator. When I googled these error messages, most of the solutions provided revolved around fixing the make command/path or something of the sort which occurs when compiled in Visual Studio.
I reiterate, these errors showed up ONLY after the inclusion of that second connect call of the global GCamera and the MainWindow. The program was compiling and running before this.
Thank you in advance, I apologize for the lengthy post and look forward to receiving any input.
You should have a file named moc_tcamera.cpp that implements the missing symbol in the build directory.
If it isn't present, you should "run qmake", and "Rebuild" your project (both actions are in Qt Creator Build menu).
Why the error occured:
qmake adds a moc (Qt's meta object compiler) step to the Makefile for all the source files that contains the macros Q_OBJECT or Q_GADGET, such file is said to be "mocable". Once a file is detected as mocable or non mocable, that status doesn't change until qmake is rerun.
QtCreator only runs qmake by itself when the .pro file changes (for example, when you add or remove a file).
It means you probably compiled the project once without the Q_OBJECT macro in the file tcamera.h, and added that macro afterward. And because you didn't need the meta object until you added the call to connect, VC++ didn't try to resolve the missing symbols.
You can get linker errors when you, say, include the header in your .pro file, but not the source. For example in your .pro file:
HEADERS += t_camera.h foo.h
SOURCES += foo.cpp
would cause you to have linker errors, typically LNK2001 and LNK2019. However, IIRC QtCreator manages the .pro files for you, right? In other words, make sure your .pro file is correct. I'd be surprised if it wasn't, but errors in the .pro file can cause the issue you're seeing.