Cannot link filesystem library in SDK - yocto

I am trying to use the filesystem library from C++17 while compiling with SDK.
I used this example.
#include <string>
#include <filesystem>
int main() {
const std::string path = "/tmp/";
for (const auto & entry : std::filesystem::directory_iterator(path))
std::cout << entry.path() << std::endl;
}
I have a problem when linking the library (only while compiling with SDK, it works on Ubuntu.)
Should I enable c++17 for SDK somehow?
Or should I add stdc++fs library to the SDK?

TOOLCHAIN_TARGET_TASK_append = " libstdc++-staticdev"

Related

Is there any way to disable Screen Capture/Screen Recording Flutter win32 app

I am trying to secure my application, Is there any way of disabling screen capture in win32 application.
Flutter for windows
Thanks in advance
Output I desire
I figured out how to disable screen capture in Flutter Windows Application
API Reference: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity
Navigate to Project/windows/runner/main.cpp
Add the below code in wWinMain method:
//DISABLE SCREEN
HWND code =window.GetHandle();
SetWindowDisplayAffinity(code, 0x00000011);
main.cpp:
#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include "flutter_window.h"
#include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.CreateAndShow(L"windows_app", origin, size)) {
return EXIT_FAILURE;
}
//DISABLE SCREEN
HWND code =window.GetHandle();
SetWindowDisplayAffinity(code, 0x00000011);
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}

Is there a way to catch a STATUS_STACK_BUFFER_OVERRUN error programmatically?

We have some C code that is throwing a STATUS_STACK_BUFFER_OVERRUN error (0xC0000409) once in a while. I can reproduce that error using the C code below. I'm using Visual Studio 2013 Update 4 on Windows 7, and I'm compiling with the /EHa and /GS flags. However, I have been unable to catch the error programmatically. The code never enters my __except block; instead, Visual Studio pops up a few dialog boxes informing me of the stack corruption. I realize that once this error occurs, the state of the program is in doubt; I'm merely trying to capture the error in hopes of locating where it is occurring in our production code. Is there a way to handle this error programmatically?
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#pragma warning(disable: 4996) // strcpy
void vulnerable(const char* str)
{
char buffer[10];
strcpy(buffer, str); // overrun the buffer
}
int main()
{
__try
{
char large_buffer[] = "This string is longer than 10 characters.";
vulnerable(large_buffer);
}
__except (GetExceptionCode() == STATUS_STACK_BUFFER_OVERRUN)
{
printf("error"); // never getting here
}
}

SDL2 issue undefined reference SDL_main

i,v downloaded SDL2 library on windows7 64bit i,m using MinGW compiler and my IDE is : eclipse Mars
so the problem is when i build my SDL program i face this problem :
C:\Users\{C}\Desktop\eclipse\MinGW\lib/libSDL2main.a(SDL_windows_main.o):SDL_windows_main.c:(.text+0x18): undefined reference toSDL_main'`
i did every thing correctly but i keep facing this issue and that,s the whole CDT build :
13:19:24 Incremental Build of configuration Debug for project
boring **** Info: Internal Builder is used for build g++
"-LC:\\Users\\{C}\\Desktop\\eclipse\\MinGW\\lib" -o boring.exe
"src\\boring.o" -lmingw32 -lSDL2main -lSDL2
C:\Users\{C}\Desktop\eclipse\MinGW\lib/libSDL2main.a(SDL_windows_main.o):SDL_windows_main.c:(.text+0x18):
undefined reference to `SDL_main' collect2.exe: error: ld returned 1
exit status 13:19:27 Build Finished (took 3s.337ms)
and here,s my source code:
#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
int main() {
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL init failed." << endl;
return 1;
}
SDL_Window *window = SDL_CreateWindow("Particle Fire Explosion",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH SCREEN_HEIGHT, SDL_WINDOW_SHOWN);,
if (window == NULL) {
SDL_Quit();
return 2;
}
bool quit = false;
SDL_Event event;
while (!quit) {
// Update particles
// Draw particles
// Check for messages/events
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
thanks;
SDL requires that you define your main exactly as main(int argc, char *argv[]). Please check if this resolves your problem.

The moment I add glew.h in my code glut related errors start appearing

I am new to C/C++ environment setup. Right now I am using Eclipse IDE. Below are the steps I have followed
After installing MinGW and running basic HelloWorld, C program
1) Copied glew32.dll and glut32.dll to "C:\MinGW\bin"
2) Copied gl.h, glew.h, glu.h and glut.h to "C:\MinGW\include\GL"
3) Copied glew32.lib, glut32.lib and OPENGL32.LIB to "C:\MinGW\lib"
4) In Project->properties->C/C++ Build->Settings->Tool Settings->MinGW C Linker->Libraries(-l) added "glew32", "glut32","glu32" and "opengl32"
5) Copied below code
Compiles properly.
The moment I uncomment the first line, ie glew.h, glut related compile errors (added below) appear, Can any one tell me where I am going wrong during setup?
//#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glut.h>
void changeViewport(int w, int h)
{
glViewport(0, 0, w, h);
}
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Pinnen is the best");
glutReshapeFunc(changeViewport);
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
Description Resource Path Location Type
undefined reference to `__glutCreateMenuWithExit' OpenGL line 549, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutCreateWindowWithExit' OpenGL line 503, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `__glutInitWithExit' OpenGL line 486, external location: c:\mingw\include\GL\glut.h C/C++ Problem
undefined reference to `glutDisplayFunc' OpenGL.c /OpenGL/src line 25 C/C++ Problem
undefined reference to `glutInitDisplayMode' OpenGL.c /OpenGL/src line 21 C/C++ Problem
//ignore
From glew webpage [delete gl include] :
Using GLEW as a shared library
in your program:
#include <GL/glew.h>
#include <GL/glut.h>
<gl, glu, and glut functionality is available here>
or:
#include <GL/glew.h>
<gl and glu functionality is available here>
Remember to link your project with glew32.lib, glu32.lib, and opengl32.lib on Windows and libGLEW.so, libGLU.so, and libGL.so on Unix (-lGLEW -lGLU -lGL).
It is important to keep in mind that glew.h includes neither windows.h nor gl.h. Also, GLEW will warn you by issuing a preprocessor error in case you have included gl.h, glext.h, or glATI.h before glew.h.

Do you suggest CooCox for Stm32f4 discovery kit?

I'm new with ARM processors, i recently bought STM32F4 Discovery Kit. Do you suggest me to begin proggraming with CooCoz or another IDE?
Sorry for English, Good work.
Yes, it is easy to use.
Download ST-LINK utility, CoIDE and gcc-arm-embedded toolchain.
Install it and configure CooCox. In "Project -> Select Toolchain Path" select directory with toolchain, by default "C:\Program Files\GNU Tools ARM Embedded\4.8 2013q4\bin"
Create new project, select stm32f407vg chip, then from repository select M4 CMSIS Core, CMSIS BOOT, RCC, GPIO. All needed files will be added to project tree.
Add code to main.c file
//basic headers
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
// delay function
void Soft_Delay(volatile uint32_t number)
{
while(number--);
}
int main(void)
{
//Peripherial clock setup
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
//Port setup
GPIO_InitTypeDef ledinit;
ledinit.GPIO_Mode = GPIO_Mode_OUT;
ledinit.GPIO_OType = GPIO_OType_PP;
ledinit.GPIO_PuPd = GPIO_PuPd_NOPULL;
ledinit.GPIO_Speed = GPIO_Speed_2MHz;
ledinit.GPIO_Pin = GPIO_Pin_15; //
GPIO_Init(GPIOD, &ledinit);
while(1)
{
// Led On
GPIO_SetBits(GPIOD, GPIO_Pin_15);
// Pause
Soft_Delay(0x000FFFFF);
// Led Off
GPIO_ResetBits(GPIOD, GPIO_Pin_15);
// PAuse
Soft_Delay(0x000FFFFF);
}
}
Select "Project -> Rebuild" and "Flash -> Program Download", blue led will start blink.