Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Package Dependency Linking Expectation Issue #4650

Closed
1 of 2 tasks
rahulkhand opened this issue Feb 13, 2025 · 6 comments
Closed
1 of 2 tasks

Swift Package Dependency Linking Expectation Issue #4650

rahulkhand opened this issue Feb 13, 2025 · 6 comments

Comments

@rahulkhand
Copy link

Description

When using the json library as a linking dependency for an xcode project target, there is an error for a missing json.o object file which never gets generated since the header is the only file that is available in the package target path. Without adding it as a link dependency then any c++ files which #include <json.hpp> will fail to find the relevant header.

Potential Solution:
Add an empty "json.cpp" file next to the "json.hpp" file in the single_include dir to trigger an object build and satisfy the linking stage

Reproduction steps

  1. In an xcode project in the toolbar at the top go to File -> Add Package Dependencies... and add the github.com/nlohmann/json.git package.

  2. Select the top-level project in the file hierarchy and go to the Build Phases column. Add the json library under the Link Binary with Libraries phase for the desired application target.

  3. Build project and yield the unexpected build error. A very similar way of triggering the error was shown live here first.

Expected vs. actual results

The actual result should be a successful build assuming c++ interoperability and dependencies were incorporated correctly. Instead developers are greeted with a missing build input file json.o at the linking stage.

Minimal code example

Error messages

`
Build input file cannot be found: '{Path-to-Xcode-dir}/DerivedData/{App-Name}-gdldgscwmcvvlfanswgyzkblkuzr/Build/Products/Debug/json.o'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?
`

Compiler and operating system

Macbook Air M2 running Sequoia 15.3 with Xcode 16.2 and Apple clang 16.0.0

Library version

3.11.3

Validation

@gregmarr
Copy link
Contributor

There is an issue on the Swift Package Manager repo for allowing this, 2 1/2 years old and no solution yet:
swiftlang/swift-package-manager#5706

@richardtop
Copy link
Contributor

The solution is mentioned in my video: https://youtu.be/DSLRObswE3Y, in fact, this user might have just solved it by going thru it.

See more discussions regarding this workaround in #4010 and #2807.

@rahulkhand
Copy link
Author

The solution is mentioned in my video: https://youtu.be/DSLRObswE3Y, in fact, this user might have just solved it by going thru it.

See more discussions regarding this workaround in #4010 and #2807.

Yes, I derived a solution that works for up to date versions from your video which should also be linked in the Issue description. I was going to propose adding the json.cpp file to the repo so at least it doesn't look like a junk file but seems @nlohmann may not like that approach based on reading the linked issues. I will close the issue if this is the case, just let me know or close it. Thanks

@nlohmann
Copy link
Owner

So can we close this issue?

@richardtop
Copy link
Contributor

@nlohmann depending if it would be OK if we add that single file to the repo so that it would work out of the box.

@nlohmann
Copy link
Owner

No, I'm sorry. I don't want to drop yet another file to the root of this project to make some package manager happy. I understand some people actually do use the library with Swift, and I apologize if you dig up this issue after failing to use the library as expected, but we already have a Package.swift.

@nlohmann nlohmann closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants