46: regex error 17 for `(dryad-bibo/v)[0-9].[0-9]', (match failed) - c++

I'm trying to determine the mime-type for several types of files using libmagic and the following bit of code:
auto handle = ::magic_open(MAGIC_MIME_TYPE);
::magic_load(handle, NULL);
// Both of these fail with the same error
// file_path being a const char* with the path to the file.
auto type2 = ::magic_file(handle, file_path);
// svg_content being an std::vector<char> with the contents of the file.
//auto type2 = ::magic_buffer(handle, svg_content.data(), svg_content.size());
if(!type2)
{
std::cout << magic_error(handle) << std::endl;
}
::magic_close(handle);
But for any file or buffer I try I receive regex error, either being or similar to:
46: regex error 17 for `(dryad-bibo/v)[0-9].[0-9]', (match failed)
For example with this .svg file:
<svg xmlns="http://www.w3.org/2000/svg" id="flag-icon-css-no" viewBox="0 0 640 480">
<path fill="#ed2939" d="M0 0h640v480H0z"/>
<path fill="#fff" d="M180 0h120v480H180z"/>
<path fill="#fff" d="M0 180h640v120H0z"/>
<path fill="#002664" d="M210 0h60v480h-60z"/>
<path fill="#002664" d="M0 210h640v60H0z"/>
</svg>
What I've tried so far:
libmagic 5.35
libmagic 5.39
libmagic 5.40
libmagic from opensource.apple
setting LC_TYPE and LANG to "C"
I'm linking against a version of libmagic that was built locally, could there be anything I have missed while building? Are any of the calls incorrect or is there something I'm missing?
I get similar errors when trying to run the related file binary that was compiled locally. Whereas when I use the file command that is available by default I do get image/svg+xml as output.
Edit
To build libmagic (for macOS and Ubuntu), I followed these steps:
Downloaded relevant release from Github
autoreconf --install
./configure
make
make install
Update
It looks like the regex at the bottom of this file is causing issues (at least for the svg):
https://github.com/file/file/blob/b56b58d499dbe58f2bed28e6b3c297fe7add992e/magic/Magdir/dataone
Update 2
Something strange going on; On the system where I've got it working, magic_version() reports 540, as expected. But on the systems where it fails with this error, magic_version() reports 538.
This makes little sense to me as I can't find that version on the system itself anywhere and when I run ./file --version in the build library, it reports file-5.40.

Very dissatisfying answer, but it was linking against GoogleTest causing this error somehow, not even running any tests, just linking against it.
I switched to using Catch2 instead and the issue was resolved.

Tested on Ubuntu 20.04.:
Clone the repo
git clone git#github.com:file/file.git
cd file/
Try this in fresh clone of the repo:
autoreconf -f -i
./configure --disable-silent-rules
make -j4
make -C tests check
And see whether there are any errors reported. After installation with make install, grab some valid xml file named as "test.xml" and put it to some folder together with this main.c:
#include <stdio.h>
#include <magic.h>
int main(void)
{
char *actual_file = "test.xml";
const char *magic_full;
magic_t magic_cookie;
/* MAGIC_MIME tells magic to return a mime of the file,
but you can specify different things */
magic_cookie = magic_open(MAGIC_MIME);
if (magic_cookie == NULL) {
printf("unable to initialize magic library\n");
return 1;
}
printf("Loading default magic database\n");
if (magic_load(magic_cookie, NULL) != 0) {
printf("cannot load magic database - %s\n", magic_error(magic_cookie));
magic_close(magic_cookie);
return 1;
}
magic_full = magic_file(magic_cookie, actual_file);
printf("%s\n", magic_full);
magic_close(magic_cookie);
return 0;
}
(Courtesy to vivithemage.)
Compile and try:
$ gcc main.c -lmagic
$ ./a.out
Loading default magic database
text/xml; charset=us-ascii
If it does not work on your system, report bug on project's bugtracker with specification of your OS and architecture. You can try to hotfix your problem by removing offending record from the file you have found in your update.

Related

Tensorflow Lite c++ Build

I have already put a question about the access violation of the TensorFlow lite c++ API. No one answered it so far, I believe the error I made is with selecting the wrong header- and library files from the Bazel build.
The steps that I have done to get the Tensorflow Lite Header and Libraries are from Youtube Tutorial and from Tensorflow.
Get Required Python (for me Python 3.9.5)
Install required Packages locally
Install Bazel (for me 3.7.2) and MSYS2 (after installation run pacman -S git patch unzip) and add it to Path
Check VS Build Tools 2019 for C++ (I have VS 19 Community with MSVC v142 & Windows 10 SDK)
Download and Unzip Tensorflow Sources from Github (Release of 2.5.3)
Inside the Tensorflow Sources, use python .\configure.py to start configure the bazel build (I only used Yes for override eigen strong inline, the rest is kept on the default value)
The I opened GitBash cmd inside the tensorflow source bazel build -c opt //tensorflow/lite:tensorflowlite
After a successful build later I get the "bazel-bin", "bazel-out", "bazel-tensorflow-2.5.3" and "bazel-testlogs" folder.
I created the following folders tensorflow/include/tensorflow/lite & core and tensorflow/include/flatbuffers for the headers and finally the tensorflow/lib for the libraries.
I copied the tensorflowlite.dll & tensorflow.dll.if.lib from the build directory (tensorflow-2.5.3\bazel-bin\tensorflow\lite) into the tensorflow/lib directory together with the flatbuffers.lib (from tensorflow-2.5.3\bazel-bin\external\flatbuffers\src)
I copied the tensorflow-2.5.3\bazel-bin\external\flatbuffers\src_virtual_includes\flatbuffers\flatbuffers headers into the tensorflow/include/flatbuffers directory
I copied the tensorflow-2.5.3\tensorflow\lite and tensorflow-2.5.3\tensorflow\core from the original sources into the tensorflow/include/tensorflow/lite & core directory.
After those steps, I could create a new VS Project and add the created linker and include information. And created the following short example to read the input layer.
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/optional_debug_tools.h"
#define TFLITE_MINIMAL_CHECK(x) \
if (!(x)) \
{ \
fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); \
exit(1); \
}
int main()
{
std::string filename = "C:/project/tflitetesting/models/classification/mobilenet_v1_1.0_224_quant.tflite";
std::unique_ptr<tflite::FlatBufferModel> model =
tflite::FlatBufferModel::BuildFromFile(filename.c_str());
tflite::ops::builtin::BuiltinOpResolver resolver;
tflite::InterpreterBuilder builder(*model, resolver);
std::unique_ptr<tflite::Interpreter> interpreter;
builder(&interpreter);
TFLITE_MINIMAL_CHECK(interpreter->AllocateTensors() == kTfLiteOk);
printf("=== Pre-invoke Interpreter State ===\n");
tflite::PrintInterpreterState(interpreter.get());
interpreter->SetAllowFp16PrecisionForFp32(true);
interpreter->SetNumThreads(1);
// Get Input Tensor Dimensions
unsigned char* input = interpreter->typed_input_tensor<unsigned char>(0);
}
But I am still receiving the access violation exception inside interpreter.h at
const Subgraph& primary_subgraph() const {
return *subgraphs_.front(); // Safe as subgraphs_ always has 1 entry.
}
What am I doing wrong? I dont want to build the shared library since the target (Coral Edge) has direct access to those functions (ex. interpreter->typed_input_tensor<unsigned char>(0); too.
The thing is, you cannot Debug a Release (Optimized) version.
with the command bazel build -c opt //tensorflow/lite:tensorflowlite you will create an "Release" version of the dll's and lib's.
Therefore just apply bazel build -c dbg //tensorflow/lite:tensorflowlite to get the debug tflite c++ version.

C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified

I am just trying to run a basic program in notepad++ and mingw32. I have attempted multiple different thing but I continue to get.
Current directory: \\THEBOX\Users\jacks_000\Documents
C:\MinGW\mingw32\bin\g++.exe -g "testpgrm"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
================ READY ================
When I run the nppexec I use the following
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\mingw32\bin\g++.exe -g "$(FILE_NAME)"
I have also tried:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"
I am just using a basic test program:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hi";
return 0;
}
I don't know if I will have issue running it in the command prompt if I save it this way or if I have done something wrong. I am running Windows 10 if that is a issue.
Current directory: \THEBOX\Users\jacks_000\Documents
I think it's because g++ can't access to a SMB share.
Try to compile the file locally.
The problem is with the location of "C:\MinGW\mingw32\bin\g++.exe". Where it is on your PC, and what is the actual filename, will depend on your installation.
For example, on my machine I have and old version in "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe", but a newer installation in another folder.
So you need to find the executable name and location of the compiler. You won't need to use the top two lines, just "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c", for example.
I did this and it gave a result of :
C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c
Process started >>>
<<< Process finished. (Exit code 0)
================ READY ================

git_remote_fetch returns error with message : "there is no TLS stream available"

I am trying to fetch from my remote repository on BitBucket. git_remote_fetch returns error with message:
there is no TLS stream available
Some ideas how to fix that?
Here is my code :
if(error = git_remote_fetch(remote, NULL,NULL,"fetch")!=0) {
const git_error *lastError = giterr_last();
cerr << "problem with fetch, error message : '" << lastError->message <<"'"<< endl;
}
I got the same error when trying to use Python and pygit2 (which in turn depends on libgit2) to pull from a git repository. I am using a self-compiled version of libgit2 (0.25.0).
Recompiling libgit2 with the following flag solved the issue: cmake -DCURL=OFF as described in issue #3786[1] of the libgit2 project.
Full process of compiling as per pygit2 documentation[2] with added flag:
$ wget https://github.com/libgit2/libgit2/archive/v0.25.0.tar.gz
$ tar xzf v0.25.0.tar.gz
$ cd libgit2-0.25.0/
$ cmake -DCURL=OFF .
$ make
$ sudo make install
Make sure to delete the build directory of libgit2 if you compiled it once earlier because otherwise the flag will have no effect.
[1] https://github.com/libgit2/libgit2/issues/3786
[2] http://www.pygit2.org/install.html#quick-install
If you use the built-in version of libgit of your OS I suggest trying to use a compiled version.

No such file or directory "ruby/config.h" when trying to compile C++ into Ruby using SWIG

I'm trying to get a basic example running using SWIG to convert a C++ file into Ruby. I have Ruby 2.0.0p451 (64 bit version) installed and I've also installed the 64-bit DevKit. I'm running Windows 7 and trying to use swigwin-2.0.12. Finally, I am using the GCC C++ compiler supplied by Mingw-builds for the 64-bit version of Windows.
I have the basic C++ hello world program as shown below.
#include <iostream>
#include <cstdlib>
using namespace std;
main()
{
cout << "Hello World!";
system("pause");
return 0;
}
At the command prompt, I use the command:
swig -module -c++ -ruby hello_world.cpp
This completes fine and produces a file titled hello_world_wrap.cxx. However, when I receive an error when I try to compile the .cxx file using the command:
g++ -fPIC -c hello_world_wrap.cxx -IC:\Ruby200-x64\include\ruby-2.0.0
The error I am receiving is:
All the research I've done has pointed me to an installation of the incorrect DevKit, but I don't think this is my issue. I've made sure to download the 64-bit version of Ruby and the DevKit. I've checked the folder specified in the error, and there is no config.h file. I'm not sure why the config.h file does not exist or why ruby.h is trying to load it.
Any thoughts?
Check that C:\Ruby200-x64\include\ruby-2.0.0\ruby\config.h exists. If not, find it and fix the path.
Update:
Check if there is a ruby.h in the same folder. If there is then just use -IC:\Ruby200-x64\include\ruby-2.0.0\ruby\x64-mingw instead. Otherwise try adding a second -I, for this extra path. I agree with you this is a little strange (not so much the former, but definitely if you have to have two -I). The script at https://groups.google.com/forum/m/#!topic/comp.lang.ruby/RpjuvXpFI30 suggests that this might be normal, I.e. you need one -I for platform-independent headers and one for platform-dependent.

Error when running OpenNI 2 class ( gcc 4.7.2 / ubuntu 12.10 )

I'm trying to compile an run a very basic program given below (test.cpp) which calls the OpenNI class. You can see the files and dirs they're in here. Sorry that some characters screws up a little bit in the browser's encoding. I'm using the linux command: tree, if you know a better command tell me and I will update it.
File Structure
I'm following the guide here, see "GCC / GNU Make".
#include < stdio.h >
#include < OpenNI.h >
using namespace openni;
int
main ( void )
{
Status rc = OpenNI::initialize();
if (rc != STATUS_OK)
{
printf("\nInitialize failed\n%s\n", OpenNI::getExtendedError());
return 1;
}
printf("Hello, world!\n");
return 0;
}
Here is what I'm running in the command line to compile it (gcc 4.7.2):
gcc test.cpp -I../OpenNI-2.0.0/Include -L/home/evan/Code/OpenNi/Init -l OpenNI2 -o test
This works fine but when I run ./test I get the following error:
Initialize failed
DeviceDriver: library handle is invalid for file libOniFile.so
Couldn't understand file 'libOniFile.so' as a device driver
DeviceDriver: library handle is invalid for file libPS1080.so
Couldn't understand file 'libPS1080.so' as a device driver
Found no valid drivers in './OpenNI2/Drivers'
Thanks, any help would be much appreciated.
Instructions from your guide says, that
It is highly suggested to also add the "-Wl,-rpath ./" to your linkage command. Otherwise, the runtime linker will not find the libOpenNI.so file when you run your application. (default Linux behavior is to look for shared objects only in /lib and /usr/lib).
It seems you have exactly this problem -- it can not find some libraries. Try to add proper rpath (seems to be /home/evan/Code/OpenNi/Init/OpenNI2/Drivers in your case) to your compilation string.
I had the same issue after compiling this little "Hello World" with Eclipse and trying to run it in the command line.
The "Wl,-rpath=./" thing did not work for me.
As also discussed here it worked for me after setting some env. variables before execution:
export LD_LIBRARY_PATH="/path/to/OpenNI2:$LD_LIBRARY_PATH"
export OPENNI2_DRIVERS_PATH="/path/to/OpenNI2/Drivers"
export LD_LIBRARY_PATH="/path/to/OpenNI2/Drivers:$LD_LIBRARY_PATH"
Somewhere I got the info that the first two lines should be enough but it was the third line which is important. I does also work just with the third line.