Shout
Shout copied to clipboard
Could not build Objective-C module 'CSSH'
I am running Xcode 11.0 on Catalina. (10.15.0). I'm getting a Could not build Objective-C module 'CSSH' error when I try to build. Sure enough CSSH isn't in my dependencies.
Package.swift import PackageDescription
let package = Package( name: "myapp", dependencies: [ .package(url: "https://github.com/jakeheis/Shout", from: "0.5.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "myapp", dependencies: ["Shout"]), .testTarget( name: "myappTests", dependencies: ["myapp"]), ] )
$ swift package update Updating https://github.com/jakeheis/Shout Updating https://github.com/IBM-Swift/BlueSocket Updating https://github.com/jakeheis/CSSH Completed resolution in 2.91s Everything is already up-to-date
$ swift package generate-xcodeproj generated: ./myapp.xcodeproj
// // Agent.swift // Shout // // Created by Jake Heiser on 3/4/18. //
import CSSH <- Could not build Objective-C module 'CSSH'
CSSH doesn't appear to be installed in the dependencies:

Any thoughts? Thanks.
Can you try running
swift package reset
swift build
and see if that happens to fix it? I've been planning to merge CSSH into this repo anyway and use the library targets introduced in Swift 4.2, so that could potentially fix it even if swift package reset doesn't.
That did not fix it. Any other suggestions? Thanks
I merged CSSH into Shout, hopefully version 0.5.4 should fix the issue
Jake,
Thanks for the update. I created a brand new project in Xcode 11.3. I used the Add Package Dependency to add Shout in but got these errors when I built it:
This might be because I have never used this feature and have got it wrong. 😀
Thanks
Andrew
On 3 Jan 2020, at 03:04, Jake Heiser [email protected] wrote:
I merged CSSH into Shout, hopefully version 0.5.4 should fix the issue
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jakeheis/Shout/issues/34?email_source=notifications&email_token=AADD7TTY7LNTMVQMLSLW2JTQ32TLJA5CNFSM4I7CR2GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIAEVWA#issuecomment-570444504, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADD7TVDH5DWSMB5QMPRQOLQ32TLJANCNFSM4I7CR2GA.
I am seeing several of the same build errors (both if I try to integrate Shout via Xcode 11's Swift Packages feature, or even if I try to build Shout itself by cloning the repo and then opening it in Xcode 11 directly).
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
^
/Users/danbrowne/Downloads/Shout-master/Sources/CSSH/shim.h:4:10: error: 'libssh2.h' file not found
#include <libssh2.h>
^
/Users/danbrowne/Downloads/Shout-master/Sources/Shout/Agent.swift:8:8: error: could not build Objective-C module 'CSSH'
import CSSH
This was using the latest 0.5.4 release, so the attempted fix doesn't appear to have worked. Any advice @jakeheis ?
I have the same issue.
Just chiming in: same issue here.
I also have the same issue
I am having the same issue with the latest 0.5.4. release. @jakeheis any feedback?
Same issue here too, also on 0.5.4 release (on Xcode 11.4, targeting iOS 13.4, although not sure it matters). Added using Xcode Package Manager. I'd love to find a fix for this as this is the exact function I have been searching for. Would love to see it in action! :-) Thank you in advance.
libssh2 is dependent of openssl.
After brew reinstall openssl
You will see:
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/[email protected]/certs
and run /usr/local/opt/[email protected]/bin/c_rehash
[email protected] is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL.
If you need to have [email protected] first in your PATH run: echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
For compilers to find [email protected] you may need to set: export LDFLAGS="-L/usr/local/opt/[email protected]/lib" export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
I have managed to build with:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib" && \
export CPPFLAGS="-I/usr/local/opt/[email protected]/include" && \
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig" && \
swift build
@gopito - thank you for the reply! This has gotten me a little closer and given me a little more insight, but I'm still having problems. Keep in mind that I'm relatively new to Xcode and I'm also using the Xcode GUI, not command line tools :)
That said, I did not have brew previously installed ... but I do now, and reinstalled the [email protected] cask and now libssh2. They both successfully installed and I can see them both in the 'Cellar' directory, along with Symbolic links in the /usr/local/opt directory. Note that my symlink in the opt directory for openssl points to the latest [email protected] module:

All good so far. Then in Xcode, after adding the Shout package using the package manager and then, under the Build Settings I added recursive elements to the Header Search Paths for both the openssl and libssh2 installs. Similarly, I've added the openssl and libssh2 libraries (*.dylib) explicitly in the Other Linker Flags. I've tried defining these both explicitly (mapped to the brew Cellar directories with specific versions) as well as using the symlinks, but here is what they look like now in the Xcode Build Settings:

However, after all of that I still get errors building the Shout package, and of course my command to:
import Shout
also fails as a result:

So, I think I'm stuck at this point. I also tried adding the export statements and PATH additions to .zshrc as you suggested above, and sourced the new .zshrc file and restarted Xcode GUI (although I'm not sure the Xcode GUI uses these ZSH environment variables), here is the output of the zsh env command:
... and still no luck. Same darn errors.
Finally, along similar lines to adding openssl paths to LDFLAGS, CPPFLAGS, and PKG_CONFIG_PATH, I added the references to the libssh2 lib/header/pkg files ...

... and restarted Xcode, rebuilt my project, and unfortunately I get the same errors while building the Shout package.
Anyway, I feel like I am very close to having this working and wouldn't doubt that I made some simple error along the way or am missing one basic step (perhaps I still haven't found the right combination of settings to point Xcode to the right spot). I can physically see the libssh2.h header file it is complaining about, I don't know why it can't ;-)
I appreciate any other advice you, @jakeheis or anybody else can offer. Thank you!
Peace.
I have the same issue, but with my SPM command line tool. For me, the build stopped working after update to Xcode 11.4. I've made some research here:
https://forums.swift.org/t/xcode-11-4b3-spm-does-not-see-brew-deps/34307/8
It does seem as though the most recent version of Swift has broken libs which depend on system libraries. It has worked for me in the command line to use
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
swift build
and Xcode 11.4.1 is able to successfully build a project when the project is generated as such:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
swift package generate-xcodeproj
Could someone see if this fixes the problem when the target is "My Mac" in Xcode?
@jakeheis is there any way to set these as flags in the SPM file? Or does it have to be done on the command line?
It does seem as though the most recent version of Swift has broken libs which depend on system libraries. It has worked for me in the command line to use
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig" swift buildand Xcode 11.4.1 is able to successfully build a project when the project is generated as such:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig" swift package generate-xcodeprojCould someone see if this fixes the problem when the target is "My Mac" in Xcode?
As far as Xcode (as opposed to command line) is concerned I can confirm this worked when generating a project from this repo. I've used the generated project in place of a framework in my own project but had to point "Import Paths" under "Swift Compiler - Search Paths" in the build settings to the CSSH folder of this repo.
It does seem to be the problem that openssl is installed in a directory that is not in the pkg-config search path. I couldn't find a way to export PKG_CONFIG_PATH from the Xcode gui, would be nice if a fix could be applied so it works out of the box with SPM without workarounds.
Edit: target used was "My Mac" as specified.
I ran into this problem attempting to use Shout in my Vapor project.
While the above mentioned export PKG_CONFIG_PATH... as proposed after brew install libssh2 works on my Mac, it does not when I build a Docker image for my Vapor project. However, I got it to work as follows:
FROM vapor/swift:5.2
...
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils
RUN apt-get install -y libssh2-1 libssh2-1-dev
# Compile with optimizations
RUN export LDFLAGS="-L/usr/lib/x86_64-linux-gnu" && \
export CPPFLAGS="-I/usr/include" && \
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig" && \
swift build \
--enable-test-discovery \
-c release \
-Xswiftc -g
During trial-and-error I had the following line after all apt-get install's:
RUN dpkg -L libssh2-1; dpkg -L libssh2-1-dev
This listed all files and folders related to those packages. This way I found the right paths to use for LDFLAGS, CPPFLAGS and PKG_CONFIG_PATH.
I must admit I'm not entirely sure if both libssh2-1 and libssh2-1-dev are needed, but this works for me. Still fine-tuning this...
See also:
- https://stackoverflow.com/questions/51023312/docker-having-issues-installing-apt-utils
- https://forums.swift.org/t/xcode-11-4b3-spm-does-not-see-brew-deps/34307/2
While it may be less than ideal, I was able to solve this issue by providing linkerSettings within Package.swift.
Example package config which is working with Shout as a dependency.
let package = Package(
name: "test",
platforms: [
.macOS(.v10_14)
],
dependencies: [
.package(name: "Shout", url: "https://github.com/jakeheis/Shout", from: "0.5.6")
],
targets: [
.target(
name: "test",
dependencies: [
.product(name: "Shout", package: "Shout")
],
linkerSettings: [
.unsafeFlags(
[
"-L/usr/local/opt/[email protected]/lib",
"-I/usr/local/opt/[email protected]/include"
],
.when(platforms: [.macOS], configuration: .release)
),
]
),
.testTarget(
name: "testTests",
dependencies: ["test"]),
]
)
Once the LinkerSettings were in place, xcode and SPM were able to be used without issue.
xcode version 11.5 swift version 5.2.4
With the above I am getting:
The package product '<Name>' cannot be used as a dependency of this target because it uses unsafe build flags.
@cloudnull, how did you get around this?
As some build flags can be exploited for unsupported or malicious behavior, the use of unsafe flags makes the products containing this target ineligible for use by other packages.
https://developer.apple.com/documentation/swift_packages/swiftsetting/3112770-unsafeflags
The package product '<Name>' cannot be used as a dependency of this target because it uses unsafe build flags.
@klmitchell2 I've not hit that issue. Are you seeing that message when you build with Xcode? Do you see the same error with swift package manager (swift build ...)?
MAC OS: macOS Catalina 10.15.5 Xcode: Xcode 11.5 iOS: iOS 13.5.1
@jakeheis : I am getting the same issues. How long are we expect a stable version of it?
If anyone have solved this issue then provide me the steps. So, I can follow it.
Thanks in advance.
@mital-defsys you can either figure it out and commit a fix yourself, or follow the solutions above. E.g. mine (for which I tend to blame brew).
I don't think it is nice to such tone ("How long are we expect a stable version of it?").
@cloudnull tried it your way with linkerSettings unsafeFlags, no success when using Package.swift opening folder with Xcode 11.6, meaning I do not generate xcode project but rather allow xcode to setup .swiftpm folder and do it instead of myself. Have you tried this way? Any success?
Still having issues with this, none of the above solutions have worked for me. Looking in the /usr/local/opt/[email protected]/lib/pkgconfig directory I'm not actually seeing the libssh2.h header that's being imported in Sources/CSSH/shim.h nor am I seeing the libssh2.pc file that swift build is warning about . Did libssl get updated with new file names or something?
$ swift --version
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.6.0
$ ls /usr/local/opt/[email protected]/lib/pkgconfig
libcrypto.pc libssl.pc openssl.pc
$ swift build
warning: failed to retrieve search paths with pkg-config; maybe pkg-config is not installed
'CSSH' libssh2.pc: warning: couldn't find pc file
ld: warning: Could not find or use auto-linked library 'ssh2'
Undefined symbols for architecture x86_64:
"_libssh2_agent_connect", referenced from:
_$s5Shout5AgentC7connectyyKF in Agent.swift.o
"_libssh2_agent_disconnect", referenced from:
_$s5Shout5AgentCfd in Agent.swift.o
"_libssh2_agent_free", referenced from:
_$s5Shout5AgentCfd in Agent.swift.o
"_libssh2_agent_get_identity", referenced from:
_$s5Shout5AgentC11getIdentity4lastAC9PublicKeyCSgAH_tKF in Agent.swift.o
"_libssh2_agent_init", referenced from:
_$s5Shout5AgentC8cSessionACs13OpaquePointerV_tKcfc in Agent.swift.o
"_libssh2_agent_list_identities", referenced from:
_$s5Shout5AgentC14listIdentitiesyyKF in Agent.swift.o
"_libssh2_agent_userauth", referenced from:
_$s5Shout5AgentC12authenticate8username3keySbSS_AC9PublicKeyCtF in Agent.swift.o
"_libssh2_channel_close", referenced from:
_$s5Shout7ChannelC5closeyyKF in Channel.swift.o
"_libssh2_channel_free", referenced from:
_$s5Shout7ChannelCfd in Channel.swift.o
"_libssh2_channel_get_exit_status", referenced from:
_$s5Shout7ChannelC10exitStatuss5Int32VyF in Channel.swift.o
"_libssh2_channel_open_ex", referenced from:
_$s5Shout7ChannelC16createForCommand8cSessionACs13OpaquePointerV_tKFZ in Channel.swift.o
"_libssh2_channel_process_startup", referenced from:
_$s5Shout7ChannelC4exec7commandySS_tKF in Channel.swift.o
"_libssh2_channel_read_ex", referenced from:
_$s5Shout7ChannelC8readDataAA18ReadWriteProcessorO0E6ResultOyF in Channel.swift.o
"_libssh2_channel_request_pty_ex", referenced from:
_$s5Shout7ChannelC10requestPty4typeySS_tKF in Channel.swift.o
"_libssh2_channel_send_eof", referenced from:
_$s5Shout7ChannelC7sendEOFyyKF in Channel.swift.o
"_libssh2_channel_wait_closed", referenced from:
_$s5Shout7ChannelC10waitClosedyyKF in Channel.swift.o
"_libssh2_channel_wait_eof", referenced from:
_$s5Shout7ChannelC7waitEOFyyKF in Channel.swift.o
"_libssh2_channel_write_ex", referenced from:
_$s5Shout7ChannelC5write4data6length2toAA18ReadWriteProcessorO0H6ResultO10Foundation4DataV_Sis5Int32VtFs0J0OySiAA8SSHErrorVGSWXEfU_ in Channel.swift.o
"_libssh2_init", referenced from:
_globalinit_33_E47B0AB8180088EC3B1503AA6C6E936F_func0 in Session.swift.o
"_libssh2_scp_send64", referenced from:
_$s5Shout7ChannelC12createForSCP8cSession8fileSize10remotePath11permissionsACs13OpaquePointerV_s5Int64VSSAA15FilePermissionsVtKFZ in Channel.swift.o
"_libssh2_session_free", referenced from:
_$s5Shout7SessionCfd in Session.swift.o
"_libssh2_session_get_blocking", referenced from:
_$s5Shout7SessionC8blockings5Int32Vvg in Session.swift.o
"_libssh2_session_handshake", referenced from:
_$s5Shout7SessionC9handshake4overy6SocketAFC_tKF in Session.swift.o
"_libssh2_session_init_ex", referenced from:
_$s5Shout7SessionCACyKcfc in Session.swift.o
"_libssh2_session_last_errno", referenced from:
_$s5Shout8SSHErrorV15mostRecentError7session13backupMessageACs13OpaquePointerV_SStFZ in SSHError.swift.o
"_libssh2_session_last_error", referenced from:
_$s5Shout8SSHErrorV4kind7session13backupMessageA2C4KindO_s13OpaquePointerVSStc33_36A87DA783DEB00A06E7AF49F9616525LlfC in SSHError.swift.o
- .systemLibrary(name: "CSSH", pkgConfig: "libssh2"),
+ .systemLibrary(name: "CSSH", pkgConfig: "libssh2", providers: [.brew(["libssh2","openssl"])])
The above change fixes it. No need to run export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
- .systemLibrary(name: "CSSH", pkgConfig: "libssh2"), + .systemLibrary(name: "CSSH", pkgConfig: "libssh2", providers: [.brew(["libssh2","openssl"])])The above change fixes it. No need to run
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
Would this work on macOS, because I'm having issues with using this SPM on macOS?
- .systemLibrary(name: "CSSH", pkgConfig: "libssh2"), + .systemLibrary(name: "CSSH", pkgConfig: "libssh2", providers: [.brew(["libssh2","openssl"])])The above change fixes it. No need to run
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"Would this work on macOS, because I'm having issues with using this SPM on macOS?
This package is only for macOS . Works for me with swift-tools-version:5.3 platforms: [ .macOS(.v10_10) ],
- .systemLibrary(name: "CSSH", pkgConfig: "libssh2"), + .systemLibrary(name: "CSSH", pkgConfig: "libssh2", providers: [.brew(["libssh2","openssl"])])The above change fixes it. No need to run
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"Would this work on macOS, because I'm having issues with using this SPM on macOS?
This package is only for macOS . Works for me with swift-tools-version:5.3
platforms: [
.macOS(.v10_10)
],
That's too bad because I've been hoping that it would be used for macOS(.v10_15)
it works with v10_15 if you are using swift-tools-version:5.3. It works for me in macOS(.v10_15) . What error are you getting ?
- .systemLibrary(name: "CSSH", pkgConfig: "libssh2"), + .systemLibrary(name: "CSSH", pkgConfig: "libssh2", providers: [.brew(["libssh2","openssl"])])The above change fixes it. No need to run
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"Would this work on macOS, because I'm having issues with using this SPM on macOS?
This package is only for macOS . Works for me with swift-tools-version:5.3 platforms: [ .macOS(.v10_10) ],
That's too bad because I've been hoping that it would be used for macOS(.v10_15)
it works with v10_15 if you are using swift-tools-version:5.3. It works for me in macOS(.v10_15) . What error are you getting ? please do a 'swift package clean' and try again