# C++ Static Library Build Issues

**URL:** <https://forums.swift.org/t/c-static-library-build-issues/74918>\
**Category:** Package Manager\
**Tags:** packagemanager, cplusplus\
**Created:** [September 24, 2024, 7:14pm UTC](https://forums.swift.org/t/c-static-library-build-issues/74918 "2024-09-24T19:14:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshavant](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@joshavant](https://forums.swift.org/u/joshavant)\
**Post date:** [September 24, 2024, 7:14pm UTC](https://forums.swift.org/t/c-static-library-build-issues/74918/1 "2024-09-24T19:14:58Z")

</div>

Hi all,

I'm trying to create an SPM module for a C++ static library.

Here's the directory structure of my SPM module:

```swift
.
├── Sources
│ └── Essentia
│ ├── include
│ │ └── essentia
│ │ ├── scheduler
│ │ │ ├── graphutils.h
│ │ │ ├── network.h
│ │ │ └── networkparser.h
│ │ ├── streaming
│ │ │ ├── accumulatoralgorithm.h
│ │ │ ├── multiratebuffer.h
│ │ │ ├── phantombuffer.h
│ │ │ ├── phantombuffer_impl.h
│ │ │ ├── sink.h
│ │ │ ├── sinkbase.h
│ │ │ ├── sinkproxy.h
│ │ │ ├── source.h
│ │ │ ├── sourcebase.h
│ │ │ ├── sourceproxy.h
│ │ │ ├── streamingalgorithm.h
│ │ │ ├── streamingalgorithmcomposite.h
│ │ │ └── streamingalgorithmwrapper.h
│ │ ├── utils
│ │ │ ├── extractor_freesound
│ │ │ │ ├── FreesoundDescriptorsSet.h
│ │ │ │ ├── FreesoundLowlevelDescriptors.h
│ │ │ │ ├── FreesoundRhythmDescriptors.h
│ │ │ │ ├── FreesoundSfxDescriptors.h
│ │ │ │ ├── FreesoundTonalDescriptors.h
│ │ │ │ └── extractor_version.h
│ │ │ ├── extractor_music
│ │ │ │ ├── MusicDescriptorsSet.h
│ │ │ │ ├── MusicLowlevelDescriptors.h
│ │ │ │ ├── MusicRhythmDescriptors.h
│ │ │ │ ├── MusicTonalDescriptors.h
│ │ │ │ ├── extractor_version.h
│ │ │ │ └── tagwhitelist.h
│ │ │ ├── tnt
│ │ │ │ ├── jama_cholesky.h
│ │ │ │ ├── jama_eig.h
│ │ │ │ ├── jama_lu.h
│ │ │ │ ├── jama_qr.h
│ │ │ │ ├── jama_svd.h
│ │ │ │ ├── tnt.h
│ │ │ │ ├── tnt2essentiautils.h
│ │ │ │ ├── tnt2vector.h
│ │ │ │ ├── tnt_array1d.h
│ │ │ │ ├── tnt_array1d_utils.h
│ │ │ │ ├── tnt_array2d.h
│ │ │ │ ├── tnt_array2d_utils.h
│ │ │ │ ├── tnt_array3d.h
│ │ │ │ ├── tnt_array3d_utils.h
│ │ │ │ ├── tnt_cmat.h
│ │ │ │ ├── tnt_fortran_array1d.h
│ │ │ │ ├── tnt_fortran_array1d_utils.h
│ │ │ │ ├── tnt_fortran_array2d.h
│ │ │ │ ├── tnt_fortran_array2d_utils.h
│ │ │ │ ├── tnt_fortran_array3d.h
│ │ │ │ ├── tnt_fortran_array3d_utils.h
│ │ │ │ ├── tnt_i_refvec.h
│ │ │ │ ├── tnt_math_utils.h
│ │ │ │ ├── tnt_sparse_matrix_csr.h
│ │ │ │ ├── tnt_stopwatch.h
│ │ │ │ ├── tnt_subscript.h
│ │ │ │ ├── tnt_vec.h
│ │ │ │ └── tnt_version.h
│ │ │ ├── MersenneTwister.h
│ │ │ ├── asciidag.h
│ │ │ ├── asciidagparser.h
│ │ │ ├── atomic.h
│ │ │ ├── audiocontext.h
│ │ │ ├── betools.h
│ │ │ ├── bpfutil.h
│ │ │ ├── bpmutil.h
│ │ │ ├── ffmpegapi.h
│ │ │ ├── jsonconvert.h
│ │ │ ├── metadatautils.h
│ │ │ ├── output.h
│ │ │ ├── peak.h
│ │ │ ├── ringbufferimpl.h
│ │ │ ├── synth_utils.h
│ │ │ ├── types.h
│ │ │ └── yamlast.h
│ │ ├── algorithm.h
│ │ ├── algorithmfactory.h
│ │ ├── algorithmfactory_impl.h
│ │ ├── config.h
│ │ ├── configurable.h
│ │ ├── connector.h
│ │ ├── debugging.h
│ │ ├── essentia.h
│ │ ├── essentiamath.h
│ │ ├── essentiautil.h
│ │ ├── iotypewrappers.h
│ │ ├── iotypewrappers_impl.h
│ │ ├── module.modulemap
│ │ ├── parameter.h
│ │ ├── pool.h
│ │ ├── range.h
│ │ ├── roguevector.h
│ │ ├── streamconnector.h
│ │ ├── streamutil.h
│ │ ├── stringutil.h
│ │ ├── threading.h
│ │ └── version.h
│ └── lib
│ └── libessentia.a
└── Package.swift

```

And here's the contents of my `Package.swift` file:

```swift
// swift-tools-version:5.7
import PackageDescription

let package = Package(
    name: "Essentia",
    products: [
        .library(
            name: "Essentia",
            targets: ["Essentia"]
        )
    ],
    targets: [
        .target(
            name: "Essentia",
            path: "Sources/Essentia",
            publicHeadersPath: "include/essentia",
            cxxSettings: [
                .headerSearchPath("include/essentia")
            ],
            linkerSettings: [
                .linkedLibrary("c++"),
                .unsafeFlags(["-LSources/Essentia/lib", "-lessentia"]),
            ]
        )
    ],
    cxxLanguageStandard: .cxx17
)

```

Notably, `essentia.h` is **not** implemented as a valid umbrella header. I added `include/essentia/module.modulemap` that looks like so:

```swift
module Essentia {
    header "scheduler/graphutils.h"
    header "scheduler/network.h"
    header "scheduler/networkparser.h"

    header "streaming/accumulatoralgorithm.h"
    header "streaming/multiratebuffer.h"
    header "streaming/phantombuffer.h"
    header "streaming/phantombuffer_impl.h"
    header "streaming/sink.h"
    header "streaming/sinkbase.h"
    header "streaming/sinkproxy.h"
    header "streaming/source.h"
    header "streaming/sourcebase.h"
    header "streaming/sourceproxy.h"
    header "streaming/streamingalgorithm.h"
    header "streaming/streamingalgorithmcomposite.h"
    header "streaming/streamingalgorithmwrapper.h"

    header "utils/extractor_freesound/FreesoundDescriptorsSet.h"
    header "utils/extractor_freesound/FreesoundLowlevelDescriptors.h"
    header "utils/extractor_freesound/FreesoundRhythmDescriptors.h"
    header "utils/extractor_freesound/FreesoundSfxDescriptors.h"
    header "utils/extractor_freesound/FreesoundTonalDescriptors.h"
    header "utils/extractor_freesound/extractor_version.h"

    header "utils/extractor_music/MusicDescriptorsSet.h"
    header "utils/extractor_music/MusicLowlevelDescriptors.h"
    header "utils/extractor_music/MusicRhythmDescriptors.h"
    header "utils/extractor_music/MusicTonalDescriptors.h"
    header "utils/extractor_music/extractor_version.h"
    header "utils/extractor_music/tagwhitelist.h"

    header "utils/tnt/jama_cholesky.h"
    header "utils/tnt/jama_eig.h"
    header "utils/tnt/jama_lu.h"
    header "utils/tnt/jama_qr.h"
    header "utils/tnt/jama_svd.h"
    header "utils/tnt/tnt.h"
    header "utils/tnt/tnt2essentiautils.h"
    header "utils/tnt/tnt2vector.h"
    header "utils/tnt/tnt_array1d.h"
    header "utils/tnt/tnt_array1d_utils.h"
    header "utils/tnt/tnt_array2d.h"
    header "utils/tnt/tnt_array2d_utils.h"
    header "utils/tnt/tnt_array3d.h"
    header "utils/tnt/tnt_array3d_utils.h"
    header "utils/tnt/tnt_cmat.h"
    header "utils/tnt/tnt_fortran_array1d.h"
    header "utils/tnt/tnt_fortran_array1d_utils.h"
    header "utils/tnt/tnt_fortran_array2d.h"
    header "utils/tnt/tnt_fortran_array2d_utils.h"
    header "utils/tnt/tnt_fortran_array3d.h"
    header "utils/tnt/tnt_fortran_array3d_utils.h"
    header "utils/tnt/tnt_i_refvec.h"
    header "utils/tnt/tnt_math_utils.h"
    header "utils/tnt/tnt_sparse_matrix_csr.h"
    header "utils/tnt/tnt_stopwatch.h"
    header "utils/tnt/tnt_subscript.h"
    header "utils/tnt/tnt_vec.h"
    header "utils/tnt/tnt_version.h"

    header "utils/MersenneTwister.h"
    header "utils/asciidag.h"
    header "utils/asciidagparser.h"
    header "utils/atomic.h"
    header "utils/audiocontext.h"
    header "utils/betools.h"
    header "utils/bpfutil.h"
    header "utils/bpmutil.h"
    header "utils/ffmpegapi.h"
    header "utils/jsonconvert.h"
    header "utils/metadatautils.h"
    header "utils/output.h"
    header "utils/peak.h"
    header "utils/ringbufferimpl.h"
    header "utils/synth_utils.h"
    header "utils/yamlast.h"

    header "algorithm.h"
    header "algorithmfactory.h"
    header "algorithmfactory_impl.h"
    header "config.h"
    header "configurable.h"
    header "connector.h"
    header "debugging.h"
    header "essentiamath.h"
    header "essentiautil.h"
    header "iotypewrappers.h"
    header "iotypewrappers_impl.h"
    header "parameter.h"
    header "pool.h"
    header "range.h"
    header "roguevector.h"
    header "streamconnector.h"
    header "streamutil.h"
    header "stringutil.h"
    header "threading.h"
    header "types.h"
    header "version.h"
    
    export *
}

```

When I build the SPM project in Xcode or run `swift build` on it, everything builds successfully.

In Xcode, on a fresh, empty, new project, I added the Package Dependency straightforwardly (e.g. Project Settings \> Package Dependencies \> +).

However, when I go to build the Xcode project with the dependency added, I get the following compiler error:

```swift
Build input file cannot be found: '/Users/joshavant/Library/Developer/Xcode/DerivedData/EssentiaTest-gduqrskidqpqctcbbjizgohcycrt/Build/Products/Debug/Essentia.o'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?

```

Any thoughts on what I might need to do here?
