Arduino / esp8266: error: section attribute not allowed for 'Pchr - c++

My Arduino program had compiled and worked correctly but something happen or I did something because now when I compile it, I get an compiler error. I have tried upgrading esp8266 v2.4.1 to 2.5.2 but then I get another error in the random.tcc header file. I am compiling my code with Visual Studio 2017 with Visual Micro. I have seen this error on the web but upgrading didn't seem to help.
Any suggestions?
OUTPUT
Adafruit_ESP8266.cpp:17: In file included from
Adafruit_ESP8266.h: 28:35: error: section attribute not allowed for 'Pchr
typedef const PROGMEM char Pchr; \\ Ditto, kindasorta
SOURCE
#include <Adafruit_ESP8266.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.println("Begin Setup");
Serial.println("End Setup");
}
// the loop function runs over and over again until power down or reset
void loop()
{
Serial.println("Begin Loop");
Serial.println("End Loop");
}

I fixed my error by removing the header file Adafruit_ESP8266.h. I must of clicked on something that included it.

Related

ESP8266[NodeMCU] LittleFS Library Problem

I'm working on Arduino IDE to implement LittleFS file system.However I get the error message as "src\LITTLEFS.cpp:17:21: fatal error: vfs_api.h: No such file or directory
#include "vfs_api.h" when I try to compile my program.
Code :
#include <Arduino.h>
#include "FS.h"
#include <LITTLEFS.h>
#define FORMAT_LITTLEFS_IF_FAILED true
void setup(){
}
void loop(){
}
Arduino version : 1.8.13
Board : NodeMCU v3(ESP12-E Module 1.0)
Flash Size : 4MB(1 MB SPIFFS)
Seems like you've chosen the ESP32 version of this project, which doesn't run on ESP8266. Try the ESP8266 version instead.

How can I create a c++ header file in Visual Studio Code?

I have a program with 3 files, and when IrRun the program via Code Runner it keeps printing errors.The icon for the "Log.hpp" file is C, not C++. It doesnt matter if I rename it to Log.h or anything, it seems that I cant create a c++ header file in vscode.
The 3 files are:
main.cpp
#include <iostream>
#include "log.hpp"
using namespace std;
int main() {
InitLog();
Log("Hello World");
return 0;
}
log.cpp
#include "log.hpp"
#include <iostream>
void InitLog() {
Log("Initializing Log");
}
void Log(const char *message) {
std::cout << message << std::endl;
}
log.hpp
#pragma once
void InitLog();
void Log(const char *message);
The error mesages are:
main.cpp: In function 'int main()':
main.cpp:5:5: error: 'InitLog' was not declared in this scope
InitLog();
^~~~~~~
main.cpp:6:5: error: 'Log' was not declared in this scope
Log("Hello World");
Need help.
Are you using Windows? Which compiler? Do you have Microsoft Build Tools installed or even Visual Studio? Are you using gcc or clang?
You must start VS Code from a developer prompt: Open a developer prompt console, navigate to the folder where you code is. Then enter
code .
Visual Studo Code will then open with the environment set up. Then open a terminal inside VSCode using Control-` and try
cl /EHsc main.cpp log.cpp
And it will create main.exe. You can run it in the terminal and it will not close... Next time you open the project you can just open the folder in VS Code, since it would then already have the json config files created
VS Code is just an IDE. So compilers must be installed and also extensions. And some JSON files and tasks must be set up. It is sometimes simple, sometimes not so simple, I believe. But doing that you will then have a powerful editor and an unbelievably flexible environment, since you can for instance run and debug code in nodejs or C or C++ or anything and even in Linux without leaving the session on your casual Windows machine.
Your question is about a specific vscode plugin called Code Runner. It's not really related to vscode. The way how Code Runner is designed will never work for multiple C++ source files. It's not the right tool for the job.
Perhaps you'd better off with Microsofts CMake Tools package for vscode. It does require you to create your own CMakeLists.txt file though. In your case you'd need nothing more than:
add_executable(log
main.cpp
log.cpp
)

C++ Stack cookie buffer overrun on UE4 with DLL

I'm trying to include a dll into unreal engine 4. So until now, I'm just trying to print a string coming from the DLL. But when i try to use the function of the DLL i immediatly got this error:
Exception thrown at 0x00007FFACC964C80 in (UE4Editor-Prototype.dll) in UE4Editor.exe: stack cookie instrumentation code detected a stack-based buffer overrun
I've check that the issue really come from the function call, if i remove it, I don't get the error.
I've try to put it in a char, string or even nothing but it didn't do anything.
I've tried to catch the error but it never succeed, unreal just crash. I succeed to get the error with visual studio debugger. When i go step by step. i can see, the DLL is found but after BeginPlay, it crash.
Here is the code in unreal which is not working:
void UMyTestComponent::BeginPlay()
{
Super::BeginPlay();
//It's just some test code, i know it's executed once, this code appears
//inside the log
UE_LOG(LogTemp, Warning, TEXT("TEEEEEEEEEEEEEEEEEST1"));
try {
//Call to the DLL, this call make UE4 crash
Test_init();
}
catch (std::exception e) {
//Nothing is ever written here
UE_LOG(LogTemp, Warning, TEXT("%s"), e.what());
}
}
here is my Dll file .h
#pragma once
#include <string>
#define PARSER_API __declspec(dllexport)
extern PARSER_API std::string Test_init();
and here is my Dll file .cpp
#include "pch.h"
#include <utility>
#include <limits.h>
#include <iostream>
#include "Test.h"
std::string Test_init()
{
return std::string("DLLLLLLLL");
}
I'm working on windows 10, UE 4.22.3 and visual studio 2019
The goal would be to catch the string and to print it in an :
UE_LOG() to print it.
So i will print "DLLLLL" just to check the correct linkage
Edit:
I've tried several formatting with __declspec(dllexport). but none is working, the C linkage too.

why I cant run this why this c++ code giving errors in visual studio ,though it is running well in code blocks after deleting #include "stdafx.h"

why this c++ code is giving error in visual studio though it runs well in code blocks after deleting #include "stdafx.h"
#include "stdafx.h"
#include <iostream>
using namespace std;
void chintumal();
int main() {
chintumal();
return 0;
}
void chintumal() {
cout << "this is anurag pradhan ! \n";
}
screenshot of visual studio with entered code
You can have only one main function in your code. Looks like you have another main defined in ConsoleApplication1.cpp file.
Actually I'm a beginner hence facing little issues ,actually i made a project in visual studio and in the same project created two files with one one main function in each, hence my code was not running !

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.