How to build Leptonica library under Google pnacl-clang++ - c++

Does anyone know how to build Leptonica library under pnacl-clang++.
I can build the library using clang++ compiler.
cd leptonica-1.71
./configure CC="clang" CXX="clang++" --enable-shared
make
I don't know how to configure pnacl-clang++ to build Leptonica library.
Per Google documentation, This is how every file is compiled separately.
e.g.
nacl_sdk/pepper_<version>/toolchain/win_pnacl/bin/pnacl-clang++ \
hello_world.cc -Inacl_sdk/pepper_<version>/include -c \
-o hello_world.o -g -O0
But, I don't want to run pnacl-clang++ separately on every individual file in the library folder. I must configure it.
Thanks.

PNaCl expects everything to be build as static libraries, not shared, though that's being worked on. For most projects the effort of targeting PNaCl will involve creating a static library build, and setting CC/CXX to pnacl-clang/pnacl-clang++.
Open source projects are often already ported on naclports (and regression-tested), but it looks like leptonica isn't one of these. I suggest looking at other projects' diff to understand what goes into building for PNaCl, and contributing your port of leptonica.
There's a bit more documentation on building.
I hope this is useful in building any project, not just leptonica :-)

Related

wxWidgets jpeg library build issue

I'm trying to build wxWidgets library into a custom path on a Fedora 27 operative system.
I achieved the wx-config file path recognition and works with the cmake execution. Also, I load libraries and include dirs based on modified wxWidgets finder cmake file that sets thewx-config custom path successfully.
But cmake does not load my wxWidgets configuration. I mean, wx_gtk2u_jpeg-3.1 builded lib could not be founded (suposed to be /usr/lib/libwx_gtk2u_jpeg-3.1.so). I need jpeg dependency from wxWidgets for my project.
I'm sure that problem is not about cmake files. However, the problem is wxWidgets compilation because cmake can found the other builded dependencies into /usr/lib/
I actually installed the libjpeg-turbo-devel package that includes the libjpeg.h needed for wxWidgets building without success of libwx_gtk2u_jpeg-3.1.so creation.
The weirdest part is that $ wx-config --libs shows the wx_gtk2u_jpeg-3.1 lib to be linked and the hint paths that it should be founded.
wxWidgets commands for building:
$ ./configure --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --enable-webviewwebkit=no --prefix=/opt/cpp_dependencies/2018Q1/usr'
$ make -j 4
$ make install
You can check out my cmake files, the cmake output and wxWidgets building output in order to reproducing it: https://gist.github.com/jjalvarezl/b70accae269ef56c56010bedf157c27f
You can see line 1543 of wxWidgets building output file that jpeg library is buildin, and, 1564 of same file, the make install command that installs all libwx_<lib_name>.so libraries into final /usr/lib path. Anyway, no one contains the needed library.
Please show the exact error message, as it's not clear what the actual problem is. What I can say, is that the different built-in versions of 3rd party libraries, such as libjpeg, are always static libraries, even when wxWidgets themselves are shared. I.e. you're never going to have libwx_gtk2u_jpeg-3.1.so, only .a.
I'd also strongly recommend using system versions of the 3rd party libraries under Unix systems. This means that your wxWidgets applications will get security updates from your OS vendor and you don't risk running into any incompatibilities due to using 2 different versions of the same library in your application.

Is there way to package Tensorflow for c++ api?

I've been developing c++ project using a Tensorflow c++ api. it just execute created tensorflow's graph from Python. I build it using bazel with Tensorflow code now. But I think it's inefficient way.
I want just Tensorflow library and header files, and Just compile my project only using Cmake.
I know how to build shared library.
bazel build -c opt --config=cuda //tensorflow:libtensorflow.so but this command just make a libtensorflow.so file. I can't find header files for build my project.
Is there way to package tensorflow library for c++? such as mvn package command.
As far as I know, there is no official distributable C++ API package. There is, however, tensorflow_cc project that builds and installs TF C++ API for you, along with convenient CMake targets you can link against. According to your description, that may be just what you need.
If your operating system is Debian or Ubuntu, you can download unofficial prebuilt packages with the Tensorflow C/C++ libraries. This distribution can be used for C/C++ inference with CPU, GPU support is not included:
https://github.com/kecsap/tensorflow_cpp_packaging/releases
There are instructions written how to freeze a checkpoint in Tensorflow (TFLearn) and load this model for inference with the C/C++ API:
https://github.com/kecsap/tensorflow_cpp_packaging/blob/master/README.md
Beware: I am the developer of this Github project.
As Floop already mentioned, his tensorflow_cc project is also a good alternative without packaging, especially if you want GPU support for the inference.
You can build tensorflow with CMake. This also creates a TensorflowConfig.cmake, which you can integrate in your project
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/cmake
Little hint: You have to build the shared lib, even if you do not need it.
You have two option: static linking and dynamic linking.
If you want to dynamic link your c++ project to TensorFlow, all you need is a --whole-archive linker flag. The necessary header files are provided by a pip install.
Generating the library is basically
bazel build -c opt --copt=-mfpmath=both --config=cuda //tensorflow:libtensorflow.so
bazel build -c opt --copt=-mfpmath=both --config=cuda //tensorflow:libtensorflow_cc.so
Having everything in place it is easy to run a TensorFlow graph in C, C++, Go (GitHub project). See the linked project for these working examples in C, C++, Go.
When building against the shared library, the headers I use are in $PROJECT_HOME/bazel-genfiles.
Adding $PROJECT_HOME/bazel-genfiles to the linker header list should be enough.

How can I compile ndpiReader.c that comes with nDPI library in Windows?

I want to create a .exe of ndpiReader.c demo program that comes with nDPI library. I was successful to compile it on Ubuntu using commands specified on their github page as bellow:
./autogen.sh
./configure
make
I have tried to cross compile it using GCC inside Ubuntu but I wasn't successful. I also tried to use the pcapExample.sln to compile it in Visual Studio 2012, but I keep getting error messages like:
Error 29 error C1083: Cannot open include file: 'ndpi_api.h': No such file or directory
Although ndpi_api.h and all other files that I get this error for already are listed in the project solution explorer.
Has anyone actually been able to make a win32 executable out of this ndpiReader.c file? If yes, please specify the steps, requirements, or a link.
nDPI lib is hosted here: https://github.com/ntop/nDPI
ndpiReader.c is hosted here: https://github.com/ntop/nDPI/tree/dev/example
pcapExample.sln is hosted here: https://github.com/ntop/nDPI/tree/dev/example/Win32
I saw from your other questions that you had already tried to compile this with CYGWIN and ran into a number of problems.
Here’s a step-by-step guide I just used to compile nDPI (including the ndpiReader.exe example):
Install CYGWIN:
Accept the default directories, and pick a mirror.
At the Select Packages step, expand the Devel category, and select the following developer packages to install:
autoconf
autoconf2.5
automake
automake1.15
binutils
cmake
cygwin-devel
gcc-core
gcc-tools-epoch2-autoconf
gcc-tools-epoch2-automake
libtool
make
pkg-config
w32api-headers
w32api-runtime
Install libpcap under CYGWIN:
Download and unpack the Winpcap Developer's pack.
Copy libpacket.a and libwpcap.a from WpdPack\Lib\ to cygwin\lib\
In cygwin\lib, copy libwpcap.a to libpcap.a
In cygwin\usr\include, create a pcap directory
Copy all headers from WpdPack\Include to cygwin\usr\include\pcap
I'm sure you've installed winpcap already as part of everything else you've tried, but double-check that the necessary (packet.dll and wpcap.dll) libraries are already in cygwin\c\WINDOWS\system32.
Now you've got all the necessary tools and libraries to compile nDPI on Windows!
Building nDPI
Download and unpack nDPI again in a clean directory, so you don't get tripped up by any issues from the previous build you tried.
Open a CYGWIN terminal, and cd into the nDPI directory.
Run autogen.sh
./autogen.sh
This should complete without any errors.
If it stops with "somepackage is missing: please install it and try again," you've missed installing a CYGWIN package that is needed to build the source.
If it stops with "Missing libpcap(-dev) library," double-check the previous steps you did to copy libpcap.a in cygwin\lib.
autogen.sh should start running the configure stage for you. (If it doesn't, or part of this stage fails, you can rerun configure after fixing any issue.)
./configure
After checking for a number of things, configure will end by creating a Makefile.
Build the nDPI library, by running make.
make
It will build the library, then try to build the examples, but fail because it can't find pcap.h
cd into the example directory, and manually compile ndpiReader.c by adding -I/usr/include/pcap to the command:
cd example/
gcc -DHAVE_CONFIG_H -I. -I.. -I../src/include -I/usr/include/pcap -g -O2 -c -o ndpiReader.o ndpiReader.c
I included my command as an example. If your compiler command is slightly different, just add -I/usr/include/pcap to what your Makefile had invoked.
Leave the example directory, and resume the make.
cd ..
make
This last step will link ndpiReader with the ndpi library, and create the executable you're looking for.

How to install protobuf on windows? (Win7x64/MinGW)

C++-Protobuf does not compile in VS2012. Now I want to use MinGW to compile it on windows. Can someone please give me some brief headwords on how to compile protobuf on Win7 x64. I already installed MinGW with the GUI installer. Google writes as MinGW setup notice that I should refer to the Unix installation notes. But I cant figure out how to use the auto tools on windows.
Edit
Okay this is what I've done until now:
$ mount C:/ WinDir
$ cd ./[...]/protobuf.2.4.1
$ ./configure
$ minGW32-make.exe
$ minGW32-make.exe check
minGW32-make.exe runs without errors, but no tests are running and I cant find libprotobuf.lib. There are some libprotobuf.dll but I need the lib, dont I?.
You should have an MSys console together with your MinGW instalation. This console provides an linux-like environment in which you should be able to use autotools normally.
If MSys is not installed, you can grab it from the MinGW site too.
cd to your directory with sources and try the usual:
$ ./configure
$ make
Some libraries cause problems on Windows but most compile well with MinGW and MSys. Come back and add more info to your question if you run into specific problems.
Edit:
minGW32-make.exe runs without errors, but no tests are running and I cant find libprotobuf.lib. There are some libprotobuf.dll but I need the lib, dont I?.
Usually for a dynamic library you'd get protobuf.dll (the dynamic library) and libprotobuf.a (the static wrapper library).
When linking, just pass -lprotobuf to the linker - it will look for both libprotobuf.a and protobuf.lib.
(.lib is another static library format, which is partially handled by MinGW but not native here.)
You will not work with a .lib file when using the MinGW toolchain. Instead, you are able to link against the dll directly. The MinGW Wiki explains this.
I could get dll and lib both. This is when you do not want static lib file and want to use dll and lib file.
You need to make following changes in Protobuf code:
Open the project in VS. Or any other editor. I use VS2015.
In libProtoBuf project settings, in C/C++ Preprocessor add following flags.
PROTOBUF_USE_DLLS; LIBPROTOBUF_EXPORTS;
Those flags will export information from profobuf using dllexport
in ur client code where you are using Protobuf, define: PROTOBUF_USE_DLLS. Which will make protobuf includes to use dllimport.
Once you do step 2, you will see both dll and lib in your output folder. Otherwise, you will always see just dll and not lib file.
Hope this helps. If not, please write a message here and I can help you getting this sorted out.

How to run C++ library with OpenCV on the other computer (linux)?

I wrote a small project using C++, OpenCV 2.2 and g++ in Ubuntu 11.04. I need to make a library (.so would be better), but I want it to run on the other computer, without OpenCV installed.
I've tried to build dynamic library using -shared and -fPIC flags for g++, and copied OpenCV .so libs to the working directory. Actually I need only core and feature2d, but actually it requested lot's of other libs, including highgui, which also has many dependencies.
I tried static linking, using -Wl,-Bstatic flags, but also unsuccessfully.
Did someone has the same problems? I would appreciate any kind of help.
It is possible to build OpenCV without dependencies from system libraries. To turn of all the dependencies for OpenCV 2.2 on Linux you can run cmake with following arguments:
cmake -DWITH_1394=OFF -DWITH_CUDA=OFF -DWITH_EIGEN2=OFF -DWITH_FFMPEG=OFF -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_OPENEXR=OFF -DWITH_PVAPI=OFF -DWITH_QT=OFF -DWITH_TBB=OFF -DWITH_UNICAP=OFF -DWITH_V4L=OFF -DWITH_XINE=OFF -DUSE_IPP=OFF -DOPENCV_BUILD_3RDPARTY_LIBS=ON ..
But in this case you will not be able to use many of functions form highgui module:
video reading and writing
working with camera
all functions working with GUI (like imshow)