Building Intel IPP with MingW - c++

I'm trying to use Intel IPP with MingW(mingw-w64\x86_64-8.1.0) using NetBeans 12.2 and also tried with Eclipse 2021-06 (4.20.0) in Win10. Specified the include("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/include") and dll's("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32") path in the project settings.
For the below sample code,
#include <iostream>
#include <ipp.h>
using namespace std;
int main(int argc, char** argv)
{
const IppLibraryVersion *lib;
IppStatus status;
Ipp64u cpuFeatures, enabledFeatures;
Ipp8u *gray= NULL;
IppiSize size;
IplImage* img = NULL; // new IplImage structure img
/* Init IPP library */
ippInit(); /* Initialize Intel(R) IPP library */
lib = ippGetLibVersion();/* Get Intel(R) IPP library version info */
printf("%s %s\n", lib->Name, lib->Version);
return 0;
}
I'm getting error,
Error: 'IplImage' was not declared in this scope;
Also, on commenting the line :IplImage* img = NULL; I get the following error,
g++ -o dist/Debug/MinGW-Windows/samplecppapplication
build/Debug/MinGW-Windows/main.o -L"C:/Program\ Files
(x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32" -lippcc -lippccg9
-lippcch9 -lippccp8 -lippccs8 -lippccw7 -lippch -lippchg9 -lippchh9 -lippchp8 -lippchs8 -lippchw7 -lippcore -lippcv -lippcvg9 -lippcvh9 -lippcvp8 -lippcvs8 -lippcvw7 -lippdc -lippdcg9 -lippdch9 -lippdcp8 -lippdcs8 -lippdcw7 -lippe -lippeg9 -lippeh9 -lippep8 -lippes8 -lippew7 -lippi -lippig9 -lippih9 -lippip8 -lippis8 -lippiw7 -lipps -lippsg9 -lippsh9 -lippsp8 -lippss8 -lippsw7 -lippvm -lippvmg9 -lippvmh9 -lippvmp8 -lippvms8 -lippvmw7 c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcc
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippccg9
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcch9 .... ...
Can you please help in fixing this and get to work using IPP ?

I tried the ipp sample with g++ compiler which comes with mingw-w64\x86_64-8.1.0 in windows10 command prompt(initialize oneapi environment before compiling the code) and it worked fine (after commenting the line :IplImage* img = NULL). I've included libraries from intel64 folder in ipp directory which comes with oneapi, as i'm using 64 bit windows machine.
g++ test.cpp -o ipptest -I "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0/include" -L "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0\redist\intel64" -lippcore

Related

libsndfile Emscripten environment

I am running just a little code using libsndfile, in the emscripten environment
#include <iostream>
#include <sndfile.h>
int main()
{
SF_INFO info;
const char * path = "~/data/somefile.wav";
SNDFILE* sf = sf_open(path,SFM_READ, &info);
if(sf == NULL)
{
std::cout<< sf_strerror(sf) << std::endl;
return 1;
}
std::cout<<info.samplerate<<std::endl;
std::cout<<"Hello world" << std::endl;
}
So ideally if I run this with normal cmake (Apple Clang compiler) everything works fine, the samplerate and hello world are printed, but when I run this with emcmake cmake (em++ compiler) and run the compiled node main.js file it says System error: no such file or directory. Who can help me with this? Who has experienced such thing?
So I figured it out.
The problem is that Emscripten has its virtual file environment. So if you want this file to be uploaded and later be seen in compiled .js file, you need to add compile flag --preload-file <FILE_PATH> , after that the file with given path will be recognized by emscripten environment.

How to fix 'The procedure entry point SDL_RWclose could not be located in the dynamic link library'

I'm trying to draw a png image to a window using the SDL_image extension, but it gives me an "Entry Point Not Found" error
I'm using SDL (2.0.9) and SDL_Image (2.0.5)
I've copied the following bin files to the executable directory
libjpeg-9.dll
libpng16-16.dll
libtiff-5.dll
libwebp-7.dll
SDL2.dll
SDL2_image.dll
zlib1.dll
main.cpp extract
#include <iostream>
#include <SDL.h>
#include <SDL_image.h>
int main( int argc, char* args[] )
{
SDL_Texture* test_tex;
SDL_Window* window = NULL;
SDL_Renderer* renderer;
if(renderer)
{
//Tested blank screen and it works
/*
SDL_RenderPresent(renderer);
SDL_Delay(2000);
*/
//Trying to use SDL_image and it fails
SDL_Surface *tmp_surface = IMG_Load("player.png");
test_tex = SDL_CreateTextureFromSurface(renderer,tmp_surface);
SDL_FreeSurface(tmp_surface);
SDL_RenderPresent(renderer);
SDL_Delay(2000);
}
...
Complied like this
g++ test.cpp ^
-IC:\dev\SDL2-2.0.9\i686-w64-mingw32\include\SDL2 ^
-IC:\dev\SDL2_image-2.0.5\i686-w64-mingw32\include\SDL2 ^
-LC:\dev\SDL2-2.0.9\i686-w64-mingw32\lib ^
-LC:\dev\SDL2_image-2.0.5\i686-w64-mingw32\lib ^
-lmingw32 ^
-lSDL2main ^
-lSDL2 ^
-lSDL2_image ^
-o test
I've tested the window with a blank renderer and it's all ok, It fails when I add the call to IMG_Load
You need another SDL_Image version. Use SDL_Image (2.0.4) instead of (2.0.5).
You can get the older versions here:
https://www.libsdl.org/projects/SDL_image/release/?C=M;O=D
(That fixed the same problem for me)
The 2.0.9 32 bit SDL2.dll gave me issues with anything other than VC++. Fortunately the 2.0.10 version is available for testing which actually works for my Code::Blocks compiled tests: https://www.libsdl.org/tmp/download-2.0.php

OpenCV 3.4.3 throwing (-212) parsing error exception (icvXMLParseTag)

I compiled OpenCV v3.4.3 with some custom arguments; static linking, 1394 driver not included and release build, see below:
cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=OFF -D WITH_1394=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
I have a custom program to compile haar cascade files into a header file, this is for file portability since I cannot have any asset files and everything has to be bundled into one binary, the below will produce the header file:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char **argv) {
string fn = "haarcascade_frontalface_alt.xml";
ifstream in(fn.c_str());
string all,line;
while (getline(in,line))
all += line + "\n";
ofstream out("opencv_data.h");
out << "const char xml[] = {";
for (size_t i=0; i<all.length(); i++) {
if (i%16==0) out << "\n";
out << int(all[i]) << ", ";
}
out << "10};\n";
return 0;
}
I'm using FileStorage (FileStorage::READ | FileStorage::MEMORY) to read the pre-produced header byte array into OpenCV, see incomplete example below:
#include "opencv_data.h"
CascadeClassifier face_cascade;
FileStorage fs(xml, FileStorage::READ | FileStorage::MEMORY);
face_cascade.read(fs.getFirstTopLevelNode()
This is working fine when compiled on macOS 10.13.6 using libc++, the problem is when compiling on Linux, standard Debian 9.4 machine compiled using g++ and static linking (-static-libstdc++) -- the binary will throw an XML parsing error, see below:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.3) /root/opencv-3.4.3/modules/core/src/persistence_xml.cpp:474: error: (-212:Parsing error) icvXMLParseTag in function '(null)(24352): Tag should start with '<''
Aborted
The debian 9.4 build works normally if I manually pull the cascade file into the program at runtime (include it as an external asset and load as a .xml file) but fails to work properly when loading via memory (via header byte array)
Cheers.

cannot compile rinside with armadillo examples

I am trying to compile the Rarmadillo example with Rinside and I keep getting:
In file included from rinside_arma0.cpp:8:0:
/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include/RcppArmadillo.h:26:6: error: #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'."
I googled it but I keep getting the source code per se. Any ideas ?
The code is :
// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo classes
//
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
#include <RInside.h> // for the embedded R via RInside
#include <RcppArmadillo.h>
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string cmd = "diag(3)"; // create a Matrix in r
arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
std::cout << m << std::endl; // and use Armadillo i/o
exit(0);
}
and compiled it using:
g++ -I/usr/local64/opt/R-2.15.2/lib/R/include -I/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/include -I"/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include" -I/usr/local64/opt/R-2.15.2/lib/R/library/RInside/include -g -O2 -Wall -I/usr/local/include rinside_arma0.cpp -L/usr/local64/opt/R-2.15.2/lib/R/lib -lR -lf77blas -latlas -llapack -L/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -L/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib -lRInside -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib -o rinside_arma0
The error you get is because Rcpp.h is included before RcppArmadillo.h, Rcpp.h is included by RInside.h.
For the magic that RcppArmadillo gives you, the file RcppArmadillo.h needs to be loaded before Rcpp.h. So I suggest you do this:
#include <RcppArmadillo.h>
#include <RInside.h>

FFMPEG Undefined Reference to 'avcodoec_open2' in C++

I have an error when compiling one of my C++ programs after updating the FFMPEG library from 0.8 to 'ffmpeg version git-2012-04-12-277f20c'
The error I get when I make my program is as follows:
-------- begin --------
Linking: Analysing_Server
./source/Encoding_Thread.o: In function `CEncoding_Thread::do_work()':
/home/Analyser/source/Encoding_Thread.cpp:155: undefined reference to `avcodec_open2'
collect2: ld returned 1 exit status
make: *** [Analysing_Server] Error 1
The relevant lines of my Make file is similar to running g++ as below:
g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS
A stripped down version of my relevant CPP code that throws the error is:
#include <stdio.h>
#include <stdint.h>
#define LOG_OUT_STREAM_BUFF_SIZE 200000
extern "C" {
/* The ffmpeg library is completely written in C, so we need to tell the C++ compiler that so it links correctly. */
#include "stdint.h"
#include "libavcodec/avcodec.h"
#include "libavutil/mathematics.h"
#include "libswscale/swscale.h"
#include "libavfilter/avfilter.h"
int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr);
}
uint8_t m_outbuf[2][LOG_OUT_STREAM_BUFF_SIZE];
unsigned int m_out_size[2];
unsigned int m_OutBuffer_ID[2];
unsigned int m_Buffer_ID; /* This is just a uniqueish stamp we give to each buffer so we can tell when they change.. */
AVCodecContext * m_CodecContex;
AVCodec * m_codec;
struct SwsContext *m_img_convert_ctx;
unsigned char* m_DataBuff;
int Output_Width, Output_Height;
int Output_Bitrate;
int main(void) {
//New version of FFMPEG calls this in avcodec_register_all
//avcodec_init();
/* register all the codecs */
avcodec_register_all();
/* Initalise the encoder */
m_codec = avcodec_find_encoder(CODEC_ID_MP2);
if (!m_codec) {
printf("Encoding codec not found\n");
}
/* init the pointers.. */
m_CodecContex = NULL;
/* Default values.. */
Output_Width = 1600;
Output_Height = 1200;
Output_Bitrate = 600000;
/* Create/setup the Codec details.. */
//Changed to work with new FFMPEG
m_CodecContex = avcodec_alloc_context3(m_codec);
avcodec_get_context_defaults3(m_CodecContex, m_codec);
/* put sample parameters */
m_CodecContex->bit_rate = Output_Bitrate;
/* resolution must be a multiple of two */
m_CodecContex->width = Output_Width;
m_CodecContex->height = Output_Height;
/* frames per second */
m_CodecContex->time_base= (AVRational){1,25};
m_CodecContex->gop_size = 10; /* emit one intra frame every ten frames */
m_CodecContex->max_b_frames=1;
m_CodecContex->pix_fmt = PIX_FMT_YUV420P; /* must be YUV for encoding.. */
AVDictionary * RetunedAVDic;
/* open it */
//Changed to work with new FFMPEG
if (avcodec_open2(m_CodecContex, m_codec, &RetunedAVDic) < 0) {
printf("could not open codec");
}
}
Unfortunately the example under 'doc/examples/decoding_encoding.c' that comes with FFMPEG no longer works because all the functions that it uses are now depreciated. My code is based on the example code and worked fine with FFMPEG 0.8 but does not compile with the newest version of FFMPEG. I have changed some of the depreciated functions to their newer versions but it still doesn't compile.
Does anyone know why I am getting this error? or does anyone have a link to an example like 'doc/examples/decoding_encoding.c' using the newest version of FFMPEG?
The relevant lines of my Make file is similar to running g++ as below:
g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS
In programming, details matter. Your link command is not sufficiently similar to the above command, or it would have worked.
You probably are putting libraries in the wrong place on the link line. The order of sources and libraries matters.
Update:
If you put the code supplied above in a CPP file, then run g++ with the supplied options, it does not work. You will get the error "undefined reference to `avcodec_open2'".
No, I don't. I get a different error (since I don't have avcodec installed at all).
If the example command already fails for you, then you should provide the error it produced, not the error from some other command, so we wouldn't have to guess what that other command might have looked like.
The order of the libraries worked for FFMPEG version 0.8, why does it not work with the latest version?
Probably because you've installed the latest libavcodec54, but didn't install the latest libavcodec-dev.