{"id":18936387,"url":"https://github.com/vaporexampleslab/tinkerevalstaticcli","last_synced_at":"2026-03-21T03:30:15.143Z","repository":{"id":133115015,"uuid":"118300559","full_name":"VaporExamplesLab/TinkerEvalStaticCli","owner":"VaporExamplesLab","description":"Sample code for StackOverflow question.","archived":false,"fork":false,"pushed_at":"2022-01-05T23:01:29.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T21:26:12.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://stackoverflow.com/questions/48363996","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VaporExamplesLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T03:17:01.000Z","updated_at":"2022-01-05T23:01:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"32d334db-153d-4b6d-a507-89a65858803a","html_url":"https://github.com/VaporExamplesLab/TinkerEvalStaticCli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaporExamplesLab%2FTinkerEvalStaticCli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaporExamplesLab%2FTinkerEvalStaticCli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaporExamplesLab%2FTinkerEvalStaticCli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VaporExamplesLab%2FTinkerEvalStaticCli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VaporExamplesLab","download_url":"https://codeload.github.com/VaporExamplesLab/TinkerEvalStaticCli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239937701,"owners_count":19721482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:07:15.557Z","updated_at":"2026-03-21T03:30:15.065Z","avatar_url":"https://github.com/VaporExamplesLab.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinkerEvalStaticCli\n\n**Question:** After `generate-xcodeproj`, what Xcode settings are needed to statically link a Swift Package Library into a simple command line executable … similar to what is produced by corresponding `swift build`?\n\n**Goal:** Produce a statically linked executable with Xcode like what is produced by `swift build` from the command line _… for the same module product._ \n\nThe issue is that the `generate-xcodeproj` produced project creates a dynamically linked product (not expected) while `swift build` produces a statically linked product (as expected).\n\n**Example:** Consider two Swift Manager Packages (SPM) packages:\n\n1. static library: [`TinkerEvalStaticLib`⇗](https://github.com/VaporExamplesLab/TinkerEvalStaticLib) with `swift package init --type library` as the starting point.\n2. command line executable: [`TinkerEvalStaticCli`⇗](https://github.com/VaporExamplesLab/TinkerEvalStaticCli) with `swift package init --type executable` as the starting point.\n\n`TinkerEvalStaticLib` is simple and expressly set to a type `.static`.\n\n_TinkerEvalStaticLib.swift_\n\n``` swift\npublic class TinkerEvalStaticLib {\n    public static func printSomething() -\u003e String {\n        let s = \"Library says, 'Hello.'\"\n        print(s)\n        return s\n    }\n} \n```\n    \n_Package.swift_\n\n``` swift\n…\nproducts: [\n    .library(name: \"TinkerEvalStaticLib\", \n    type: .static, // expressly set to be a static library\n    …\n```\n\n`TinkerEvalStaticCli` is also simple and has `TinkerEvalStaticLib` as a dependency.\n\n_main.swift_\n\n``` swift\nimport TinkerEvalStaticLib\nlet _ = TinkerEvalStaticLib.printSomething() \n```\n\n_Package.swift_\n\n``` swift\n…\nname: \"TinkerEvalStaticCli\",\ndependencies: [\n  .package(\n    url: \"git@github.com:VaporExamplesLab/TinkerEvalStaticLib.git\",\n    .branch(\"master\") ),\n],\n…\n```\n\n**Observation:**\n\n1. In the `TinkerEvalStaticCli` directory, `swift build` will create a standalone relocatable, statically linked executable.\n\n```\nprompt\u003e ./TinkerEvalStaticCli_spm \nLibrary says, 'Hello.'\n```\n\n2. However, the Xcode project created with `swift package generate-xcodeproj` creates a dynamically linked executable that requires the separate library.\n\n```\nprompt\u003e ./TinkerEvalStaticCli_xc \ndyld: Library not loaded: @rpath/TinkerEvalStaticLib.framework/Versions/A/TinkerEvalStaticLib\n  Referenced from: /Users/…/./TinkerEvalStaticCli_xc\n  Reason: image not found\nAbort trap: 6\n```\n\n**Note:** One would expect that an `swift package generate-xcodeproj` generated Xcode project would build a static linked binary (instead of a dynamic linked binary) similar to the static linked binary produced by the corresponding `swift build`. So, this question is for a workaround to a current SPM `generate-xcodeproj` limitation. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaporexampleslab%2Ftinkerevalstaticcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaporexampleslab%2Ftinkerevalstaticcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaporexampleslab%2Ftinkerevalstaticcli/lists"}