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

[SR-3484] Swift PM fails to build package with C++ and ObjC++ targets #5145

Closed
swift-ci opened this issue Dec 25, 2016 · 1 comment
Closed
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3484
Radar None
Original Reporter ryanw (JIRA User)
Type Bug
Status Closed
Resolution Duplicate
Environment

macOS Sierra, XCode 8.2 (Swift 3.0.2)

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: ed70ce6225158c628b30720d82695ade

duplicates:

Issue Description:

In a nutshell:
The Swift PM has multiple failures building a package with C++ library and ObjC++ targets.

Steps to reproduce:

git clone https://github.com/tokyovigilante/AtlasGenerator
swift build

I have a swift command line project which I would like to add a number of packages to via the Swift PM. However I am unable to build the C++ library and ObjC++ wrappers.

Source at Github

Here's my Package.swift:

import PackageDescription

let package = Package(
    name: "AtlasGenerator",
    targets: [ 
        Target(name: "msdfgen"),
        Target(name: "MSDFGenBridge", dependencies:["msdfgen"]),
        Target(name: "AtlasGenerator", dependencies:["MSDFGenBridge"])
    ],
    dependencies: [
        .Package(url: "https://github.com/jkandzi/Progress.swift", majorVersion: 0)
    ]
)

Essentially the structure is:
AtlasGenerator, the command line tool, which depends on MSDFGenBridge which is the ObjC wrapper around the C++ library msdfgen.

This works fine as separate targets when manually plugged into an Xcode project (as included with the library) however when running swift build, I get:

Linking msdfgen
Undefined symbols for architecture x86_64:
...

With various stdlib symbols.

Running with -Xlinker -lc++ allows the C++ library to build, but then fails to link the ObjC++ wrapper with:

Linking MSDFGenBridge
Undefined symbols for architecture x86_64:
  "_CGAffineTransformMakeScale", referenced from:
      +[MSDFGenBridge generateMSDF:width:height:shapeDesc:translateX:translateY:edgeThreshold:autoFrame:printMetrics:scaledBounds:] in MSDFGenBridge.mm.o
  "_OBJC_CLASS_$_NSObject", referenced from:
      _OBJC_CLASS_$_MSDFGenBridge in MSDFGenBridge.mm.o
  "_OBJC_METACLASS_$_NSObject", referenced from:
      _OBJC_METACLASS_$_MSDFGenBridge in MSDFGenBridge.mm.o
  "__objc_empty_cache", referenced from:
      _OBJC_METACLASS_$_MSDFGenBridge in MSDFGenBridge.mm.o
      _OBJC_CLASS_$_MSDFGenBridge in MSDFGenBridge.mm.o
ld: symbol(s) not found for architecture x86_64

Clearly it should be able to find the ObjC frameworks itself, but if I help it out with -lObjC:

Undefined symbols for architecture x86_64:
  "_CGAffineTransformMakeScale", referenced from:
      +[MSDFGenBridge generateMSDF:width:height:shapeDesc:translateX:translateY:edgeThreshold:autoFrame:printMetrics:scaledBounds:] in MSDFGenBridge.mm.o
ld: symbol(s) not found for architecture x86_64

Basically it can't find CoreGraphics.framework. If I supply -framework CoreGraphics to the swift command I get the message:

Linking msdfgen
ld: unknown option: -framework CoreGraphics

Which is clearly not the case because if i use -v to get the invocation then run it manually with the -framework switch it compiles fine.

@ankitspd
Copy link
Member

ankitspd commented Jan 5, 2017

You can use this command to build your package until we support custom flags:

$ swift build -Xlinker -lObjC -Xlinker -framework -Xlinker CoreGraphic

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants