0

I'm trying to import Imebra into a basic swift 5 command line project using Xcode 12. I followed the official steps but I failed. I can summarise the whole structure:

The structure of the project is just

./
├── main.swift
├── Data
   └── DX_0.dcm
├── Imebra
   └── CMakeLists.txt
   └── docs
   └── examples
   └── library
   └── test
   └── wrappers
   └── build_imebra_macos

The main swift file is

// main.swift

import Foundation

print("Hello, Imebra!")

do {
   let pDataSet = try ImebraCodecFactory.load(fromFile: "PathToDicomFileFromExecutable")
    let pImage = try pDataSet.getImageApplyModalityTransform(0)
   print("The image width is", pImage.width)
} catch {
   print(error)
}

Following the documentation, I compile the library by going to the build_imebra_macos folder and running

build_imebra_macos % cmake -GXcode -DCMAKE_BUILD_TYPE=Release ..
build_imebra_macos % cmake --build . --config Release

The build is successful and the new folder Release has the dynamic library. Now in Xcode project of the CL Swift application, SwiftyImebra.xcodeproj, I followed the next instruction "open the target Build Settings and under “Swift Compiler/ObjectiveC Bridging Header” specify the path to imebra_location/wrappers/objectivec/include/imebraobjc/imebra.h.”, with Imebra_location changed to Imebra.

Then when I build I get the error

Showing All Messages
Undefined symbol: _OBJC_CLASS_$_ImebraCodecFactory

I'm new in Swift and I guess I need to specify somewhere in Xcode where the source or the dynamic library is. However, I am not sure about this either as we have generated a cpp dynamic library so this can only interact with objective-C (?). I apologise if this is a basic question...

In addition, I'd like to learn how to use Imebra as a static library with swift.

user91676
  • 41
  • 4

1 Answers1

0

The imebra dynamic library must be added to the project.

Drag the imebra.dylib (generated into your build folder build_imebra_macos) into your project.

Additionally, specify the folder containing the dylib into the "Library search path" in the compiler options.

Paolo Brandoli
  • 4,681
  • 26
  • 38
  • Hi Paolo! After dragging the generated .dylib files into "Link Binary With Libraries" (Build Phases) and specifying the Library Path I got at runtime: ```dyld: Library not loaded: @rpath/libimebra.5.dylib Referenced from: PathToDerivedDataFolder Reason: no suitable image found. Did find: /usr/local/lib/libimebra.5.dylib: code signature in (/usr/local/lib/libimebra.5.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?) ``` – user91676 Jun 09 '21 at 19:08
  • I would not like to remove the validation layer. I checked the signatures again and they are in development. – user91676 Jun 09 '21 at 19:10
  • Move the library to the location where the executable is so it can find it when it runs, or configure xcode to copy the dll to the executable location. – Paolo Brandoli Jun 09 '21 at 19:33
  • I found out that the dylib must be also build with Team ID. It didn't need to copy/move the dll to the executable as long as the folder was specified in "Library Search Paths". Xcode12 seems to be more restrictive – user91676 Jun 10 '21 at 16:05
  • A better way though, would be to use XCODE_EMBED_FRAMEWORKS and set the target PROPERTY `XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY` to TRUE. Could you maybe add this hints as well to your answer and I will accept it? – user91676 Jun 10 '21 at 16:16
  • The hardcoded, not recommended, way was to change the Imebra's main project CMakeList.txt file with ```cmake project("imebra") # Signing & Capabilities set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "YOURTEAM") set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development") ``` and then generate and build as in the Description of this question. – user91676 Jun 10 '21 at 16:27