There is not such a file called "SDL2.h" - c++

I run KDE Neon 20.04 and whenever i try to run this command block in Sublime Text i get this error.
#include "SDL2.h"
#include "SDL2_image"
#include <iostream.h>
int main(int argc, char* args[])
{
std::cout << "Yay" << std::endl;
return 0;
}
SDL2.h there is no such file or directory

You have to install SDL development libraries first. You can install it using the command sudo apt-get install libsdl2-dev.
You are also including sdl headers wrong.
This is the correct way.
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

Related

log4cplus ConsoleAppender does not work in container

I'm trying to containerize my application but I'm having trouble getting log4cplus working. Bottom line up front, logging works when running on the host, but not in the container when I'm logging from long running loops. Its seems like a buffer somewhere is not getting flushed. A minimal example follows.
Additionally, removing the long lived loop removes the issue, presumably log4cplus flushes one last time before tearing down. Lengthening the sleep duration did not seem to help.
main.cpp
#include <iostream>
#include <unistd.h>
#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
#include <log4cplus/initializer.h>
int main(int argc, char **argv)
{
std::cout << "Sanity Check" << std::endl;
auto log4cplus = ::log4cplus::Initializer();
std::string logconfig("log4cplus_configure.ini");
::log4cplus::PropertyConfigurator::doConfigure(logconfig);
auto logger = ::log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
while (true) {
LOG4CPLUS_ERROR(logger, "Sleeping...");
// std::cout << "cout sleep..." << std::endl; // uncomment to get log messages working
sleep(1);
}
return 0;
}
log4cplus_configure.ini
log4cplus.rootLogger=INFO, MyConsoleAppender
log4cplus.appender.MyConsoleAppender=log4cplus::ConsoleAppender
log4cplus.appender.MyConsoleAppender.layout=log4cplus::PatternLayout
log4cplus.appender.MyConsoleAppender.layout.ConversionPattern=[%-5p][%d] %m%n
Dockerfile
FROM rockylinux:latest
RUN dnf install -y boost-system
COPY ./build/sandbox /
COPY ./log4cplus_configure.ini /
CMD ["/sandbox"]
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set (CMAKE_CXX_STANDARD 17)
# Project executable and library
add_executable(sandbox main.cpp)
target_link_libraries(sandbox
PUBLIC liblog4cplus.a
PUBLIC pthread
PUBLIC boost_system
)
Not sure why, but adding log4cplus.appender.MyConsoleAppender.ImmediateFlush=true to log4cplus_configure.ini solved my issue.

Problems with building OpenCv with Xcode. Cannot find opencv2/opencv.hpp file

I have installed OpenCv with Homebrew on my MacOs. I have added libopencv 4.0.1.dylib in Xcode. When I try to build, Xcode cannot find the files. Any suggestions?
I changed my path but still have problems.
Main code:
#include <iostream>
#include <opencv4/opencv2/opencv.hpp>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Build settings including path:
Error messages:

Processing png in c++ with opencv and png++

Here is link for png++ :http://savannah.nongnu.org/projects/pngpp/
What I'm doing wrong?
I installed opencv for OS X by command in terminal:"brew install opencv" and I have problems with using library png++.
#include <iostream>
#include "png++/png.hpp"
using namespace std;
int main(int argc, const char * argv[])
{
png::image< png::rgb_pixel > image("74");
for(int i=0;i<image.get_width();i++)
{
for(int j=0;j<image.get_height();j++)
{
image[i][j]=png::rgb_pixel(255-image[i][j].red, 255-image[i][j].green, 255-image[i][j].blue);
}
}
image.write("output.png");
return 0;
}
And I have next errors:
error messages
Problem was, that I install opencv with brew, which I installed on Yosemite. When I updated brew on ElCapitan and reinstalled opencv, errors disappeared.

How do I get package versions in c++? (linux)

I've been writing a program that needs a wine version of 2.6 or later. I'd like to get it as a boolean, so I've been trying to use the code below:
#include <string>
#include <iostream>
#include "WineCheck.h"
#include <cstdlib>
using namespace std;
bool checkForWine()
{
// Create variables for checking wine state
bool wineIsThere = false;
bool wineIsVersion = false;
// Check dpkg if wine is there
if (string(system("dpkg -l | cut -c 4-9 | grep \\ wine\\ ")) == " wine ")
{
wineIsThere = true;
// Check version
if (double(system("wine --version | cut -c 6-8")) >= 2.6)
wineIsVersion = true;
}
// Return
if (wineIsThere && wineIsVersion)
return true;
else
return false;
}
First, it's my opinion you shouldn't bother with this. Wine 2.6 should just be included as a dependency in your configuration script, and/or your package file. Targeting a specific package management system in your program source code is not a good idea if you want to maintain portability to other GNU/Linux distributions that don't use that packager.
To answer your question though. There are two ways I found you can do this. You can check /var/lib/dpkg/status. Read through the file line by line until you get to this section. If you don't find the section, or the Status: ... line doesn't say installed then wine is not installed. The Version: ... line will tell you what version is installed. I verified this method works by installing and uninstalling Wine on Debian Wheezy. You didn't say what distro you're working with, but it's obvious you're using the Debian Packaging system, so this should work on Ubuntu and other Debian based distributions as well.
$cat /var/lib/dpkg/status
...
Package: wine
Status: install ok installed
Priority: optional
Section: otherosf
Installed-Size: 80
Maintainer: Debian Wine Party <pkg-wine-party#lists.alioth.debian.org>
Architecture: amd64
Version: 1.4.1-4
...
The other option is use libdpkg. I found an example that lists all installed packages.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
#include <dpkg/pkg-array.h>
#include "filesdb.h"
const char thisname[] = "example1";
int
main(int argc, const char *const *argv)
{
struct pkg_array array;
struct pkginfo *pkg;
int i;
enum modstatdb_rw msdb_status;
standard_startup();
filesdbinit();
msdb_status = modstatdb_open(msdbrw_readonly);
pkg_infodb_init(msdb_status);
pkg_array_init_from_db(&array);
pkg_array_sort(&array, pkg_sorter_by_name);
for (i = 0; i < array.n_pkgs; i++) {
pkg = array.pkgs[i];
if (pkg->status == stat_notinstalled)
continue;
printf("Package --> %s\n", pkg->set->name);
}
pkg_array_destroy(&array);
modstatdb_shutdown();
standard_shutdown();
}

Eclipse and OpenCV on Ubuntu

I have installed Eclipse+CDT and OpenCV with:
$ sudo apt-get install libcv1 libcv-dev libcvaux1 libcvaux-dev \
libhighgui1 libhighgui-dev \
opencv-doc \
python-opencv
After that I've opened Eclipse and created a new c/c++ project.
So I've typed this code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage* img = 0;
img=cvLoadImage("C:/.../Pictures/immagine.jpg"); // carica l'immagine
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); // crea la finestra
cvShowImage("mainWin", img ); // mostra l'immagine
cvWaitKey(0); // wait for a key
cvReleaseImage(&img ); //rilascia l'immagine
system("PAUSE");
return 0;
}
The problem is that I have these errors returned:
Unresolved inclusion: <cv.h>
Unresolved inclusion: <highgui.h>
But in my eclipse workspace project I have these libraries under /usr/include...
What may be wrong?
Thanks.
Open a terminal and execute:
pkg-config --cflags opencv
On my system it returns:
-I/usr/local/include/opencv -I/usr/local/include
Those are the directories you'll have to add on Eclipse to compile your application.
Or, you could try replacing your includes for:
#include <opencv/cv.h>
#include <opencv/highgui.h>