-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Comments
There is an issue on the Swift Package Manager repo for allowing this, 2 1/2 years old and no solution yet: |
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 |
So can we close this issue? |
@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. |
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 |
Description
When using the
json
library as a linking dependency for an xcode project target, there is an error for a missingjson.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 stageReproduction steps
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.Select the top-level project in the file hierarchy and go to the
Build Phases
column. Add the json library under theLink Binary with Libraries
phase for the desired application target.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
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
develop
branch is used.The text was updated successfully, but these errors were encountered: