'How to add a objective-c library into a Swift project on Linux?

I have this objective-c library:

GNUmakefile

include $(GNUSTEP_MAKEFILES)/common.make

LIBRARY_NAME = libone
libone_OBJC_FILES = libone.m

-include GNUmakefile.preamble

-include $(GNUSTEP_MAKEFILES)/library.make

-include GNUmakefile.postamble

libone.h

#import <Foundation/Foundation.h>

@interface HelloObjc: NSObject
   @property char * name;
   -(char *) msg;
@end

libone.m

#include "libone.h"

@implementation HelloObjc

-(id) init {
   self.name = "Hello, World!";
   return self;
}

-(char *) msg {
   return self.name;
}

-(char *) name {
   return self.name;
}

-(void) setName: (char *) name {
   self.name = name;
}

@end

Which compiles without errors or warnings, but when I try integrate with a swift project generated with the swift package manager, I get the error:

<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/home/kleber-manjaro/Documentos/swift_test/libone_objc/libone.h"
         ^
/home/kleber-manjaro/Documentos/swift_test/libone_objc/libone.h:1:9: note: in file included from /home/kleber-manjaro/Documentos/swift_test/libone_objc/libone.h:1:
#import <Foundation/Foundation.h>
        ^
/usr/include/Foundation/Foundation.h:30:9: note: in file included from /usr/include/Foundation/Foundation.h:30:
#import <GNUstepBase/GSVersionMacros.h>
        ^
/usr/include/GNUstepBase/GSVersionMacros.h:359:16: error: 'objc/blocks_runtime.h' file not found
#      include <objc/blocks_runtime.h>
               ^
/home/kleber-manjaro/Documentos/swift_test/executable/Sources/executable/main.swift:3:8: error: could not build C module 'objc_library'
import objc_library

I have this module to wrap the library:

Package.swift

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

    import PackageDescription
    
    let package = Package(
        name: "objc_library",
        dependencies: [
            // Dependencies declare other packages that this package depends on.
            // .package(url: /* package url */, from: "1.0.0"),
        ]
    )

module.modulemap

module objc_library [system] {
  header "/home/kleber-manjaro/Documentos/swift_test/libone_objc/libone.h"
  link "/home/kleber-manjaro/Documentos/swift_test/libone_objc/obj/libone.so"
  export *
}

and this executable:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "executable",
    dependencies: [
        .package(path: "../objc_library"),
    ],
    targets: [
        .executableTarget(
            name: "executable",
            dependencies: ["objc_library"]),
    ]
)

main.swift

import objc_library

let hello = HelloObjc()
print(hello.msg())

Amyone can tell me how to fix this? My guess it is probably the swift package manager uses a different compiler to build the objective-c project (even the binary files already available on the path specified on the module). Is it possible choose which compiler should be use to build the library, or tell the package manager to not build the library again (instead use the files already generated)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source