#StackBounty: #java #android #cmake INSTALL_FAILED_MISSING_SHARED_LIBRARY Causes app to not install

Bounty: 50

Hey guys I WAS getting the error

More than one file was found with OS independent path 'lib/x86_64/libopencv_java3.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

the link takes me to a page with a release notes for android 4.2, so there is nothing pretaining to my problem,

I am using a Documentscanner library buitl with opencv and that uses jnilibs and the problem I have is with that jnilibs

so

I looked through the Android Dev Guide and came across this

Automatic packaging of prebuilt dependencies used by CMake
Prior versions of the Android Gradle Plugin required that you explicitly package any prebuilt libraries used by your CMake external native build by using jniLibs. You may have libraries in the src/main/jniLibs directory of your module, or possibly in some other directory configured in your build.gradle file:

    sourceSets {
        main {
            // The libs directory contains prebuilt libraries that are used by the
            // app's library defined in CMakeLists.txt via an IMPORTED target.
            jniLibs.srcDirs = ['libs']
        }
    }

With Android Gradle Plugin 4.0, the above configuration is no longer necessary and will result in a build failure:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> More than one file was found with OS independent path 'lib/x86/libprebuilt.so'

External native build now automatically packages those libraries, so explicitly packaging the library with jniLibs results in a duplicate. To avoid the build error, move the prebuilt library to a location outside jniLibs or remove the jniLibs configuration from your build.gradle file.

So now after following the above IE Moving the library/ removing from my gradle.build etc.
The app builds and starts to install but then I get the error

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_MISSING_SHARED_LIBRARY

Help would be appreciated


Get this bounty!!!

#StackBounty: #c++ #cmake #clang #llvm #clion Unknown CMake command "add_clang_executable"

Bounty: 50

I am trying to build a clang tool, and I am trying to debug it using CLion. However, I can’t get it to compile as a standalone binary. Currently I have this in my CMakeLists.txt:

add_clang_executable(clang_my_tool my_tool_util.h my_tool_util.cpp ClangMyTool.cpp)

target_link_libraries(clang_my_tool PRIVATE clangTooling)

However, it’s giving me the error message:

Unknown CMake command "add_clang_executable".

I know I need to add an directory, but I don’t know which one to add.

My llvm directory looks something like this:

llvm
|-build
  |- ...
|
|-clang
  |-tools
    |-clang_my_tool
      |-ClangMyTool.cpp
      |-my_tool_util.h
      |-my_tool_util.c
      |-CMakeLists.txt
|- ... other directories...

What do I add to my CMakeLists.txt?


Get this bounty!!!

#StackBounty: #cmake Cannot generate a safe runtime search path for target caffe because files in some directories may conflict with li…

Bounty: 50

I am trying to install this code https://github.com/NVlabs/ssn_superpixels but get an error at the cmake .. step

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_LIBRARY (ADVANCED)
    linked by target "caffe" in directory /home/haziq/ASTAR/scripts/ssn_superpixels/lib/video_prop_networks/lib/caffe/src/caffe

So I deleted the build folder, recreated it and cd into it and ran cmake .. -DCUDA_cublas_LIBRARY=/usr/lib/x86_64-linux-gnu/libcublas.so.9.1 but now get the following messages.

CMake Warning at src/caffe/CMakeLists.txt:20 (add_library):
  Cannot generate a safe runtime search path for target caffe because files
  in some directories may conflict with libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at src/caffe/test/CMakeLists.txt:29 (add_executable):
  Cannot generate a safe runtime search path for target test.testbin because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target extract_features
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target device_query because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target convert_imageset
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target test_net because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target net_speed_benchmark
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target compute_image_mean
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target train_net because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target finetune_net because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target
  upgrade_net_proto_binary because files in some directories may conflict
  with libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target
  upgrade_net_proto_text because files in some directories may conflict with
  libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target
  upgrade_solver_proto_text because files in some directories may conflict
  with libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at tools/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target caffe.bin because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.


CMake Warning at python/CMakeLists.txt:9 (add_library):
  Cannot generate a safe runtime search path for target pycaffe because files
  in some directories may conflict with libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.

I found a post here CMake cannot resolve runtime directory path that provides a solution for find_library and find_package but mine is add_library. Anyway I tried fixing the first CMake warning

CMake Warning at src/caffe/CMakeLists.txt:20 (add_library):
  Cannot generate a safe runtime search path for target caffe because files
  in some directories may conflict with libraries in implicit directories:

    runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/haziq/anaconda3/envs/ssn/lib

  Some of these libraries may not be found correctly.

by editing line 20 of src/caffe/CMakeLists.txt by replacing add_library(caffe ${srcs}) with add_library(caffe ${srcs} NO_DEFAULT_PATH) but now get this message.

CMake Error at src/caffe/CMakeLists.txt:20 (add_library):
  Cannot find source file:

    NO_DEFAULT_PATH

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

What can I try next?


Get this bounty!!!

#StackBounty: #apt #c++ #cmake #g++ #boost Trying to build with boost filesystem: relocation … can not be used when making a shared o…

Bounty: 100

Ubuntu 18.04, boost 1.65, g++ 7.5.0, cmake 3.10.2, GNU make 4.1. Pretty much everything at the default version for ubuntu 18.04.

I’m trying to port software that uses a number of different boost components to an NVidia Jetson TX2 board… which uses the aforementioned version of ubuntu on it’s dev board and host machine.

The hurdle I’m trying to clear at the moment is that linking the first shared lib in cmake: add_library(<name> SHARED ...) fails in g++ with the error from the title. The ‘blah blah blah’ portion mentions a specific entry point within boost filesystem.

I conclude that I need to rebuild boost filesystem with the requested build flags, -fPIC.

Do I need to download the boost source directly and rebuild it, or can I do something with the apt installed -dev boost module[s]?

I’ll also need to cross compile them for arm (currently on amd64) so any advice there would be welcome too, but mostly just trying to get boost to link here.


Get this bounty!!!

#StackBounty: #cmake #libgit2 Could not find libgit2 in CMake

Bounty: 100

I am doing my first steps in CMake and I have a Hello World example where I would like to use libgit2. My directory structure is the following:

- main.cpp
- CMakeLists.txt
- cmake/Modules/Findlibgit2.cmake
- libs/libgit2/include/git2.h
- libs/libgit2/debug/git/git2.lib
- libs/libgit2/debug/git/git2.dll

I would like to link it either statically, or dynamically, at least it works for the beginning. But when I execute CMake, I receive the error message below. Could anyone help me with this?

Not searching for unused variables given on the command line.
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
[cmake]   Could NOT find libgit2 (missing: GIT2_LIBRARY GIT2_INCLUDE_PATH)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
[cmake]   cmake/Modules/Findlibgit2.cmake:15 (find_package_handle_standard_args)
[cmake]   CMakeLists.txt:6 (find_package)

Findlibgit2.cmake

# Find git2 Library
#
#  GIT2_INCLUDE_DIRS - where to find git2.h, etc.
#  GIT2_LIBRARIES    - List of libraries when using libgit2.
#  GIT2_FOUND        - True if libgit2 is found.

# GIT2_INCLUDE_PATH
find_path(GIT2_INCLUDE_PATH NAMES git2.h)
# GIT2_LIBRARY
find_library(GIT2_LIBRARY NAMES git2)

# handle the QUIETLY and REQUIRED arguments and set GIT2_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libgit2 REQUIRED_VARS GIT2_LIBRARY GIT2_INCLUDE_PATH)


if (GIT2_FOUND)
  set(GIT2_INCLUDE_DIR  ${GIT2_INCLUDE_PATH})
  set(GIT2_INCLUDE_DIRS ${GIT2_INCLUDE_PATH})
  set(GIT2_LIBRARIES    ${GIT2_LIBRARY})
endif()

mark_as_advanced(
  GIT2_INCLUDE_PATH
  GIT2_LIBRARY
)

CMakeLists.txt


cmake_minimum_required(VERSION 2.8.9)
project (backend)

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
find_package(libgit2 REQUIRED)

include_directories(${LIBGIT2_INCLUDE_DIR})
link_directories("backend/libs/libgit2/debug")
add_executable(backend main.cpp)


Get this bounty!!!

#StackBounty: #c++ #c #cmake CMake – Changing shared library link options

Bounty: 200

I want to manipulate the linker call in my linker trampoline python script, but for the life of me I cannot get CMake to respect the CMAKE_CXX_CREATE_SHARED_LIBRARY value. It always uses the CMAKE_CXX_COMPILER for linking. If I switch to an add_executable and instead use CMAKE_CXX_LINK_EXECUTABLE this works perfectly. Is there anyway to convince CMake to respect the setting of CMAKE_CXX_CREATE_SHARED_LIBRARY?

A trivial CMakeLists.txt

cmake_minimum_required( VERSION 3.12 )

project( mylib )

include( CMakePrintSystemInformation )

add_library( mylib SHARED mylib.cpp )

A toolchain excerpt

I’ve tried this in both a toolchain file and an -C pre-cache option.

set( CMAKE_LINKER "/path/to/linker_trampoline.py" )
set( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> --CMAKE_CXX_COMPILER <CMAKE_CXX_COMPILER> --CMAKE_SHARED_LIBRARY_CXX_FLAGS <CMAKE_SHARED_LIBRARY_CXX_FLAGS> --LANGUAGE_COMPILE_FLAGS <LANGUAGE_COMPILE_FLAGS> --LINK_FLAGS <LINK_FLAGS> --CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> --SONAME_FLAG <SONAME_FLAG> --TARGET_SONAME <TARGET_SONAME> --TARGET <TARGET> --OBJECTS <OBJECTS> --LINK_LIBRARIES <LINK_LIBRARIES>" CACHE STRING "" FORCE )


Get this bounty!!!

#StackBounty: #c++ #cmake Generate DLL configuration type with CMake

Bounty: 50

I’m using CMake to generate my Visual Studio solutions. Right now, CMake generates two configuration Release and Debug, under a single project. Both configs builds a win32 (.exe) application.

This works great, but I would also like to generate a third configuration, that builds a DLL instead. I’m aware that in CMake we can use add_library(LibraryName SHARED [files]) to generate a separate a project that creates builds a DLL target, but that is not what I want. Instead, I would like to generate a DLL configuration in visual studio, along side Debug and Release.

I can get the configuration by adding set(CMAKE_CONFIGURATION_TYPES Release Debug DLL) in CMakeList, but I’m not sure how to go about actually configuring it. How do I make this custom configuration actually build a DLL? If possible, I would also like to customize the output name and directory of this configuration, just like how I’m able to with CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE etc.

Is this possible?


Get this bounty!!!

#StackBounty: #python #cmake #setuptools setuptools "eager_resources" to executable directory

Bounty: 300

I maintain a Python utility that allows bpy to be installable as a Python module.

Unfortunately, platform differences and Blender runtime expectations makes support for this tricky at times.

Currently, one of my big goals is to get the Blender addon scripts directory to install into the correct location. The directory (simply named after the version of Blender API) has to exist in the same directory as the Python executable.

Unfortunately the way that setuptools works (or at least the way that I have it configured) the 2.79 directory is not always placed as a sibling to the Python executable. It fails on Windows platforms outside of virtual environments.

However, I noticed in setuptools documentation that you can specify eager_resources that supposedly guarantees the location of extracted files.

https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-resource-extraction
https://setuptools.readthedocs.io/en/latest/pkg_resources.html#resource-extraction

There was a lot of hand waving and jargon in the documentation, and 0 examples. I’m really confused as to how to structure my setup.py file in order to guarantee the resource extraction. Currently, I just label the whole 2.79 directory as “scripts” in my setuptools Extension and ship it.

Is there a way to write my setup.py and package my module so as to guarantee the 2.79 directory’s location is the same as the currently running python executable when someone runs

py -3.6.8-32 -m pip install bpy

Besides simply “hacking it in”? I was considering writing a install_requires module that would simply move it if possible but that is mangling with the user’s file system and kind of hacky. However it’s the route I am going to go if this proves impossible.

Here is the original issue for anyone interested.

https://github.com/TylerGubala/blenderpy/issues/13

My build process is identical to the process descsribed in my answer here

https://stackoverflow.com/a/51575996/6767685


Get this bounty!!!

#StackBounty: #dynamic-linking #cmake #ld #guix #guixsd cmake cannot find some libraries in GuixSD

Bounty: 250

I am trying to compile Xash3D on GuixSD v1.0.0 and gcc 8.3.0.

In essence, ld cannot find crt1.o, crti.o, and libgcc_s.so, and it is quite possible that just like before, after linking or installing these 2 c objects and libgcc, cmake will halt with yet a further error regarding other other dependencies.

As is shown below, ld is giving me errors, that ctr1.o and ctri.o are missing. These files exist under a different directoy, under /gnu/store/{specificProgramName}, however, I surprisingly wasn’t able to make a symbolic link to ~/.guix_profile, where other libraries sit, even with root access. There are multiple versions of them with different sizes so I would assume that they are only for those specific programs. Furthermore. ~/.guix_profile seems to emulate the root directory of a Unix system, however /usr is missing from both the root directory, and ~/.guix_profile, so I would not know where to link them even if I found the copied it from another distro.

Anyways, here is what is printed/logged by the following command (which is instructed as the recommended way of installing Xash3D)

sudo cmake -DHL_SDK_DIR=../hlsdk -DXASH_SDL=yes -DXASH_VGUI=yes -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" -DCMAKE_EXE_LINKER_FLAGS="-m32" ../ && sudo make
    Run Build Command:"/home/nick/.guix-profile/bin/make" "cmTC_7635d/fast"
    /home/nick/.guix-profile/bin/make -f CMakeFiles/cmTC_7635d.dir/build.make CMakeFiles/cmTC_7635d.dir/build
    make[1]: Entering directory '/home/nick/xash3d/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o
    /home/nick/.guix-profile/bin/gcc   -m32    -o CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o   -c /home/nick/xash3d/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_7635d
    /gnu/store/nrsbv2df55abwji1gsb1ilf22n3rc1xa-cmake-3.13.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7635d.dir/link.txt --verbose=1
    /home/nick/.guix-profile/bin/gcc -m32     -rdynamic CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o  -o cmTC_7635d 
    /home/nick/.guix-profile/bin/ld: cannot find crt1.o: No such file or directory
    /home/nick/.guix-profile/bin/ld: cannot find crti.o: No such file or directory
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/libgcc.a when searching for -lgcc
    /home/nick/.guix-profile/bin/ld: cannot find -lgcc
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
    /home/nick/.guix-profile/bin/ld: cannot find libgcc_s.so.1
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/libgcc.a when searching for -lgcc
    /home/nick/.guix-profile/bin/ld: cannot find -lgcc
    collect2: error: ld returned 1 exit status
    make[1]: *** [CMakeFiles/cmTC_7635d.dir/build.make:87: cmTC_7635d] Error 1
    make[1]: Leaving directory '/home/nick/xash3d/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_7635d/fast] Error 2

Much like Debian, Guix has a bash command for package installation: “guix install $PACKAGE” however its library of ~10,000 does not include one with the name ‘gcc-multilib’ which would have fixed the problem in Debian. Perhaps there is an alternative package that includes this and other libraries.

I am looking for a solution that does not involve using Wine. Solving the libgcc problem alone might not be sufficient, so in order to arrive at a genuine solution, I will be trying any advice left in the comments (there is no danger to me, the OS is installed in an isolated environment on a USB key).


Get this bounty!!!