boost 1.74+ jni ndk compilation cmake project - boost

I would like to compile boost for Android JNI CMake project.
I tried with this repo
https://github.com/moritz-wundke/Boost-for-Android
but fail build for boost v1.78 with ndk23..
Is there any tutorial or prebuilt how to do it on CMakeLists.txt project.
Thanks for help

I am using https://github.com/Orphis/boost-cmake in my CMake Android NDK projects and it works fine, you can look at this project https://github.com/nkh-lab/ndk-vsomeip-hello-world as a reference. The only extra thing you need to do is add FindBoost.cmake to serve find_package( Boost ) if you use it in your cmake files.

Related

Why OpenCV 4.5.2 doesn't have apps built

I installed OpenCV 4.5.2 using the Windows installer and when I looked in the apps folder, I couldn't find some apps (create_samples, train_cascade). So, I downloaded the code and I generated visual studio projects using CMake. After I built all those project, again, in the app folder there were no project files to build those apps.
I also run cmake . in an app directory, but this error came out:
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at CMakeLists.txt:4 (ocv_add_application):
Unknown CMake command "ocv_add_application".
-- Configuring incomplete, errors occurred!
See also "C:/opencv/opencv-master/apps/createsamples/CMakeFiles/CMakeOutput.log".
this is the CMakeLists.txt file that I run:
file(GLOB SRCS *.cpp)
ocv_add_application(opencv_createsamples
MODULES opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d opencv_videoio
SRCS ${SRCS})
In all honesty, last time that I used CMake was 10 years ago and I really would like an hand to figure this out.
Thanks
STACK:
CMake 3.20.3
OpenCV 4.5.2
Python 3.9.5
Visual Studio 16.10.0
Wndows 10
I found out why this is happening. In opencv 4.5 (I didn't check other versions), the line in the cmake file that generate the solution for traincascade and createsamples, are explicitly commented out. This because building those apps will generate more than 600 errors! Let's hope this problem will be fixed soon.
from https://github.com/opencv/opencv/issues/13231
These apps has been disabled during legacy C API removal. Rewriting them
with C++ API was not an option because it is too easy to break them
and hard to test.
Also modern approaches via DNN provides much better results - just
compare OpenCV face detector with CascadeClassifier and DNN.

Build Release version of abseil-cpp static binary libs under Windows

I am using abseil-cpp in my C++ project built under Visual Studio 2019 / Windows 10.
Using CMake (not Visual Studio built-in makefile support) and following the static binaries instructions I have built a set of libraries and header files which I can then successfully link into a standard Visual Studio solution.
The issue I have is that the library builds with a build type of Debug, which means that I cannot link them into a Release build of my application.
What I need is to build a Release version of the abseil-cpp libraries. However the for the life of me I cannot figure out how to coax CMake / Abseil build process to do this!
I have tried the following, all of which are either ignored or error:
Add set(CMAKE_BUILD_TYPE Release) to the CMakeLists.txt file in the root of the abseil-cpp source tree
Add -DCMAKE_BUILD_TYPE=Release to the cmake .. -DCMAKE_INSTALL_PREFIX=~/Source/CMakeProject/install step given in the instructions
Add -DCMAKE_BUILD_TYPE=Release to the cmake --build . --target install step given in the instructions
Can anyone suggest what I need to do to build a Release version of static binary libraries?
Ian

Cross compiling for arm using crystax NDK

The android ndk supplied by google is unable to compile call to c++11 functions such as std::to_string() and std::stoul etc. {I had tried it in r10b one from the official site}. So the suggestion in SO was to try crystax NDK. I have downloaded and placed the root folder next to the google's NDK. All I changed in my root CMakeLists.txt file was:
from:
set(PLATFORM_PREFIX "/some-path/android-ndk-r10b/platforms/android-19/arch-arm")
set(PLATFORM_FLAGS "-fPIC -Wno-psabi --sysroot=${PLATFORM_PREFIX}")
set(CMAKE_CXX_FLAGS "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "")
To:
set(PLATFORM_PREFIX "/some-path/android-ndk-r8-crystax-1/platforms/android-14/arch-arm")
set(PLATFORM_FLAGS "-fPIC -Wno-psabi --sysroot=${PLATFORM_PREFIX}")
set(CMAKE_CXX_FLAGS "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "")
and cmake command-line from:
cmake .. -DCMAKE_CXX_COMPILER=/some-path/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -DCMAKE_C_COMPILER=/some-path/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -DANDROID_BUILD=ON -DANDROID_NDK_ROOT=/some-path/android-ndk-r10b
To:
cmake .. -DCMAKE_CXX_COMPILER=/some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -DCMAKE_C_COMPILER=/some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -DANDROID_BUILD=ON -DANDROID_NDK_ROOT=/some-path/android-ndk-r8-crystax-1
ie., changed from normal ndk to crystax-ndk. The program was compiling fine previously till it tried to compile a file with call to std::to_string() etc. But after the change Cmake gives an error that it is unable to compile a simple test program because:
/some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.7/../../../../arm-linux-androideabi/bin/ld:
error: cannot find -lcrystax
I can see libcrystax.a and .so in directorie:
/some-path/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a
I tried adding link_directories("path-to-above") right at the beginning of the CMakeLists.txt file too, but that didn't solve it either.
It should find it there (after i supply the --sysroot etc above) just like the normal ndk. So how should this be solved ? Any other cmake variable to be set or something ?
I don't know how your cmake-based build system works, but actually if you properly add path /some-path/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a to linker search paths, it should find libcrystax and link with it successfully.
Please note that NDK have several parts separated each from other - i.e. sysroot, libcrystax, C++ library - all are separated. It is done to work with NDK build system which offer some flexibility choosing C++ standard library implementation, and NDK build system know where to find all of them. In your case this approach is not so good so I suggest you first make standalone toolchain, which contains all things assembled together. In other words, it would be classic cross-compile toolchain which contains sysroot, libcrystax and GNU C++ standard library in places known to compiler/linker without passing of any additional options.
To create such toolchain, cd to NDK root directory and run the following command:
./build/tools/make-standalone-toolchain.sh --system=linux-x86_64 --toolchain=arm-linux-androideabi-4.7 --platform=android-14 --install-dir=$HOME/arm-linux-androideabi
Then use $HOME/arm-linux-androideabi as full standalone toolchain for your cmake-based build system.
Please note, however, that application built with CrystaX NDK r8 will not run on newest Android 5.0 due to changes in Bionic (libc). Previous Android versions (<=4.4) are all fine. We fixed that issue (and many others) in upcoming r10 release which is on final testing stage. In the meantime you could adopt your project to our r8 release and quickly switch to r10 when it done - the same approach will work with r10 as well as with r8.

Statically link Boost Thread 1.56 lib in an Xcode 6 project

I have a very simple Xcode 6 project in which I'm trying to link to boost_thread and boost_system statically. I've build the libraries (I have the libboost_thread.a and libboost_system.a), I've included all the right header/library search paths, flags etc as I do with any other static lib in the project and the project builds successfully, yet when I run it, it gives me a runtime dlopen error that it can't find the boost_thread.dylib lib ?!
I do not link to any dylib version of any boost lib, only those two static ones. Why is it trying to dynamically load a library? Can anyone give me a hint on what's this all about?
Thanks
The quick fix:
Clean out boost and run bjam again with link=static
The explanation for anyone that stumbles on this, here's what the problem was:
I had build the entire boost package with its default config. That, however, for whatever reason does not include the static libs for system and thread. Running bjam after that sith link=static did infact build the libs but for whatever reason, they were pointing to the dylibs...

Installing and Linking OpenCV 2.4.3 on 64 bit windows with CMake

I am currently attempting to transition a CMake project from Linux to Windows that is dependent on OpenCV, but I'm having trouble linking the libraries to the executable.
I've posted the approximate CMakeLists.txt file below with some private stuff left out:
project(my_project_name)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_CXX_FLAGS "-g -Wall")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
FIND_PACKAGE(OpenCV REQUIRED)
IF(NOT OpenCV_FOUND)
MESSAGE(FATAL_ERROR "OpenCV not found")
ENDIF()
SET(PROJECT_HDRS
#headers here
)
SET(PROJECT_SRCS
#sources here
)
add_executable(${PROJECT_NAME} ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS})
This CMakeLists.txt file works just fine on Linux, but has trouble linking on Windows. My first instinct was that it was a bad install of OpenCV? Here are the approximate steps I used while installing OpenCV
Download OpenCV 2.4.3 executable (a self-extracting archive)
Extract to some directory
Use CMake-Gui to configure and generate OpenCV.sln
Open in Visual Studio C++ 2010 Express and build the ALL_BUILD project in Debug and Release configurations
Build the INSTALL project
When I try to build my own project, I get back the errors "undefined reference to 'cv::waitKey(int)' errors, which makes me think that it's a linker issue. I've attempted pointing to the .lib files directly, such as:
target_link_libraries(${PROJECT_NAME} C:/someDirectory/opencv_core243.lib)
but I still get back the same errors.
I've also attempted the methods in described in these StackOverflow threads:
here and here.
I apologize beforehand if I'm missing something obvious, but this is more or less the first time I've developed on windows and I'm running out of ideas.
to my knowledge the problem is that visual studio2010 or vc++2010 comes with .net framework 4.5
Downgrade it to .net framework4 (i.e. uninstall .net 4.5 and install 4.0).
That would solve the problem...
I hit my head to my table solving the above problem..
or else
patch the visual c++ with new Service pack
it´s a little bit late but... let´s go
for me this tutorial was perfect
http://kevinhughes.ca/tutorials/opencv-install-on-windows-with-codeblocks-and-mingw/

Resources