How to integrate Imebra v5 to a swift command line project

193 views Asked by At

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.

1

There are 1 answers

6
Paolo Brandoli On

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.