Header 'libintl.h' not found - Struggling with System Library Dependency


I am trying to create a module.modulemap to wrap gettext library, but swift cannot find its headers.

gettext is available in the path, and it is installed with brew. Can anyone help with properly including its headers?

Thanks for the help!

I managed to make it build if nothing is used by specifying the full path to the header file.

module cgettext [system] {
    umbrella header "/usr/local/Cellar/gettext/0.22.3/include/libintl.h"
    link "/usr/local/Cellar/gettext/0.22.3/lib/libintl.dylib"
    export *

However, as soon as I am trying to use any of its functions, the linking fails with an error such as:

ld: warning: Could not find or use auto-linked library '/usr/local/Cellar/gettext/0.22.3/lib/libintl.dylib': library '/usr/local/Cellar/gettext/0.22.3/lib/libintl.dylib' not found
ld: Undefined symbols:
  _libintl_setlocale, referenced from:

Currently used like this:

import cgettext

func greet() -> String {
    libintl_setlocale(LC_ALL, "")
    return "hello world"

and here is the Package.swift

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

import PackageDescription

let package = Package(
    name: "GetTextSwift",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
            name: "GetTextSwift",
            targets: ["GetTextSwift"]
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .systemLibrary(name: "cgettext", providers: [
            name: "GetTextSwift", dependencies: [
            name: "GetTextSwiftTests",
            dependencies: ["GetTextSwift"]

Few updates as I have made some progress.

I switched to my M1 device and now the Homebrew has a different root. However, it now includes all the gettext headers in its include folder.

I changed the module.modulemap file to the following:

module cgettext [system] {
    umbrella header "/opt/homebrew/include/libintl.h"
    link "intl"
    export *

And now calling it with swift test -Xlinker -L/opt/homebrew/lib/ works perfectly.

I will experiment more. My end goal of this experiment is to be able to wrap system provided gettext in an easy to import swift package on all swift supported OSes. I am just not too sure how realistic that would be now.