Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run app from installdir, but from build-Release #157

Open
bylowerik opened this issue Aug 21, 2022 · 1 comment
Open

Cannot run app from installdir, but from build-Release #157

bylowerik opened this issue Aug 21, 2022 · 1 comment

Comments

@bylowerik
Copy link

bylowerik commented Aug 21, 2022

I have tweaked the CMakeLists.txt from the example in order to link to OpenCV. This seems to work for ios and mac. I can run the toy code on the simulator.

An issue though is that if I build with -DCMAKE_INSTALL_PREFIX=../mac-lib and -DPLATFORM=MAC_ARM64, then I cannot run the executable under ./mac-lib/Test.App/Contents/MacOS/TestApp. But I can run ./build/Release/Contents/MacOS/TestApp.

When I run from mac-lib I get:

Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: 7BC035B9-D9BF-463A-821F-F89B8C4DFFEB
CrashReporter Key:   21F36FD2-7188-AE2F-1B85-FE079442FAD3
Hardware Model:      MacBookAir10,1
Process:             TestApp [49666]
Path:                /Users/USER/*/TestApp.app/Contents/MacOS/TestApp
Identifier:          leetal.com.helloworld
Version:             0.1 (0.1)
Code Type:           ARM-64 (Native)
Role:                Default
Parent Process:      launchd [1]
Coalition:           leetal.com.helloworld [32208]

Date/Time:           2022-08-21 22:11:01.1997 +0200
Launch Time:         2022-08-21 22:11:01.1853 +0200
OS Version:          macOS 12.5 (21G72)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))
Exception Subtype: UNKNOWN_0x32 at 0x00000001049bc000
Exception Codes: 0x0000000000000032, 0x00000001049bc000
VM Region Info: 0x1049bc000 is in 0x1049bc000-0x1049c0000;  bytes after start: 0  bytes before end: 16383
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  mapped file                 1049bc000-1049c0000    [   16K] r-x/r-x SM=COW  ...t_id=ad270cb7
      mapped file                 1049c0000-1049c4000    [   16K] rw-/rw- SM=COW  ...t_id=ad270cb7
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: CODESIGNING 2 

Highlighted by Thread:  0

Backtrace not available

The CMakeLists.txt is looking like this (I have added OpenCV on different places and the project name):

cmake_minimum_required (VERSION 3.2)
project (videoprocessing-ios)
enable_testing()

enable_language(CXX)
enable_language(OBJC)

MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )
MESSAGE( STATUS "CMAKE_OBJC_FLAGS: " ${CMAKE_OBJC_FLAGS} )

# Add some sanitary checks that the toolchain is actually working!
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(kqueue sys/event.h HAVE_KQUEUE)
if(NOT HAVE_KQUEUE)
  message(STATUS "kqueue NOT found!")
else()
  message(STATUS "kqueue found!")
endif()

find_library(APPKIT_LIBRARY AppKit)
if (NOT APPKIT_LIBRARY)
  message(STATUS "AppKit.framework NOT found!")
else()
  message(STATUS "AppKit.framework found! ${APPKIT_LIBRARY}")
endif()

find_library(FOUNDATION_LIBRARY Foundation)
if (NOT FOUNDATION_LIBRARY)
  message(STATUS "Foundation.framework NOT found!")
else()
  message(STATUS "Foundation.framework found! ${FOUNDATION_LIBRARY}")
endif()

find_library(UIKIT_LIBRARY UIKit)
if (NOT UIKIT_LIBRARY)
  message(STATUS "UIKit.framework NOT found!")
else()
  message(STATUS "UIKit.framework found! ${UIKIT_LIBRARY}")
endif()

# Hook up XCTest for the supported plaforms (all but WatchOS)
if(NOT PLATFORM MATCHES ".*WATCHOS.*")
  # Use the standard find_package, broken between 3.14.0 and 3.14.4 at least for XCtest...
  find_package(XCTest)
  # Fallback: Try to find XCtest as host package via toochain macro (should always work)
  find_host_package(XCTest REQUIRED)
endif()

# Includes
include_directories(${CMAKE_SOURCE_DIR}/include)

# Make sure try_compile() works
include(CheckTypeSize)
check_type_size(time_t SIZEOF_TIME_T)

#OpenCV
find_package( OpenCV REQUIRED PATHS "thirdparty/installdir/opencv_mac/lib/cmake/opencv4/" NO_DEFAULT_PATH)
include_directories( ${OpenCV_INCLUDE_DIRS} )

# Source files
set(SOURCES
  src/VideoProcessing.cpp
  src/VideoProcessingWrapperObjC.mm
)

# Headers
set(HEADERS
  include/VideoProcessing.hpp
  include/VideoProcessingWrapperObjC.h
)

# Library
if(BUILD_SHARED)
  add_library (videoprocessing SHARED ${SOURCES} ${HEADERS})
  target_link_libraries(videoprocessing ${FOUNDATION_LIBRARY} ${OpenCV_LIBS})
  target_compile_definitions(videoprocessing PUBLIC IS_BUILDING_SHARED)
  message(STATUS "Building shared version...")
else()
  add_library (videoprocessing STATIC ${SOURCES} ${HEADERS})
  target_link_libraries(videoprocessing ${FOUNDATION_LIBRARY} ${OpenCV_LIBS})
  message(STATUS "Building static version...")
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX ${videoprocessing-ios_SOURCE_DIR}/../videoprocessing-app/videoprocessing-lib CACHE PATH "Install path" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

# Executable
if(PLATFORM MATCHES "MAC.*")
  set(APP_NAME TestApp)
  add_executable (${APP_NAME} MACOSX_BUNDLE src/main.cpp)
  set_target_properties(${APP_NAME} PROPERTIES
          BUNDLE True
          MACOSX_BUNDLE_GUI_IDENTIFIER leetal.com.helloworld
          MACOSX_BUNDLE_BUNDLE_NAME helloworld
          MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
          MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1"
          )
  # Link the library with the executable
  target_link_libraries(${APP_NAME} videoprocessing ${OpenCV_LIBS})
endif()

# Debug symbols set in XCode project
set_xcode_property(videoprocessing GCC_GENERATE_DEBUGGING_SYMBOLS YES "All")

# Installation
if(PLATFORM MATCHES "MAC.*")
  install(TARGETS ${APP_NAME}
          BUNDLE DESTINATION . COMPONENT Runtime
          RUNTIME DESTINATION bin COMPONENT Runtime
          LIBRARY DESTINATION lib
          ARCHIVE DESTINATION lib/static)

  # Note Mac specific extension .app
  set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app")

  # Directories to look for dependencies
  set(DIRS ${CMAKE_BINARY_DIR} ${OpenCV_INSTALL_PATH}/lib)

  install(CODE "include(BundleUtilities)
    fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")")

  set(CPACK_GENERATOR "DRAGNDROP")
  include(CPack)
else()
  install(TARGETS videoprocessing
          LIBRARY DESTINATION lib
          ARCHIVE DESTINATION lib/static)
endif()
install (FILES ${HEADERS} DESTINATION include)

The error says it is related to code signing, but why would that not apply to the executable in the build library?

@leetal
Copy link
Owner

leetal commented Aug 21, 2022

I cannot answer that question sadly. I don't know enough about the macOS launch daemon to know specifics, but I'd assume that the packaged app is somehow treated differently and requires notarization or at least signing of the executable. When running binaries by invoking them from command line they are usually spawned from the terminal process, thus running a standalone executable might work from command line as long as the executable is not enclosed in a .app container. But the error is as you said definitely tied to signing, which you also could check via the console.app application for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants