Setting C compile flags in xcode - ios

I've been trying to compile some C files to use in XCode that uses Openssl as a dependency for encryption. When compiling with clang the code compiles fine. I read a few posts on here like Setting C++ compile flags in xcode that says to put the flags under Other Linker Flags but I still couldn't get it to recognize it.
Here is the compiling command that works on the command line:
Flags in XCode:
The error in XCode:

Solution thanks to #WhozCraig
Add the include folder in "Header Search Paths" and library folder in "Library Search Paths"
Then put -lcrypto to link the files under "Other Link Flags"

Related

Why can't I get rid of libstdc++?

Since upgrading to xcode 10 beta 6 I'm getting the error
ld: library not found for -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I know that libstdc++ has been removed from the iOS simulator but the project and all the targets have C++ Standard Library set to libc++, not libstdc++.
The project has nothing set in Other Linker Flags. The summary of the Other Links Flags for the target includes -stdlib=libstdc++
but when I double-click on it to edit it, it isn't in the list.
What is it that's sneaking libstdc++ in? Any help would be greatly appreciated!
It turned out the problem was that one of my dependencies was using libstdc++, so Cocoapods was adding the -stdlib=libstdc++ to the linker flags for the project.
The solution was to update the dependency to a newer version that had been built against libc++.
If anyone else has trouble identifying which dependency is using libstdc++ then I recommend removing $(inherited) from your target's linker flags. That will cause the linker to report missing symbols from the place that's using it, giving away which library has the problem.

Error building xcode project when i add a library with extension .a

I have an Xcode project and I need to add a static library with extension .a who sent me for integrated a functionality. I added the library in Build Phases - Link Binary With Libraries, but when I compile my project with this library I added, I does not compile and shows this error:
could not parse object file /routelibrary/libraryname.a(IosHttp.o): 'Unknown attribute kind (45)Unknown attribute kind (45)Unknown attribute kind (45)', using libLTO version 'Apple LLVM 7.0.0 (clang-700.0.72)' for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea on how can I solve it?
One possible reason is missing Other Linker Flags in your target build settings.
First check if you need to set any Other Linker Flags in documentation of your static library, and if yes, what that flag is.
For example so many libraries needs -ObjC as Other Linker Flags.
To find Other Linker Flags, do following.
Select Build Targets in your Xcode project.
select Build Settings.
In Search Box type Other Linker Flags
check and set your flags here.

How to use Realm (installed with Carthage) with a framework in a Swift app?

I'm working on an iOS App and a Watchkit App.
I read a few things regarding best practices and I decided to create a custom framework, as NathashaTheRobot advise here:
https://realm.io/news/architecting-app-apple-watch-natashatherobot/
So I'm trying to use Realm in my framework.
I followed the installation instructions for Carthage:
Add github "realm/realm-cocoa" to your Cartfile.
Run carthage update.
Drag RealmSwift.framework and Realm.framework from the
Carthage/Build/iOS/ directory to the “Linked Frameworks and
Libraries” section of your Xcode project’s “General” settings.
On your application targets’ “Build Phases” settings tab, click the
“+” icon and choose “New Run Script Phase”. Create a Run Script with
the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Realm.framework
$(SRCROOT)/Carthage/Build/iOS/RealmSwift.framework
Then I added my framework to the Target Membership of both Realm.framework and RealmSwift.framework.
But when I try to build the project, I get this error:
ld: framework not found Realm for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Then I gave a shot to lipo:
$ lipo -info Carthage/Build/iOS/Realm.framework/Realm
Architectures in the fat file: Carthage/Build/iOS/Realm.framework/Realm are: i386 x86_64 armv7 arm64
Do you have any ideas of what I might be doing wrong here? Thank you.
EDIT:
OK so I found the problem and it was totally unrelated to Realm...
It looks like I deleted the Headers and Resources sections of my framework Build Phases somehow (which were and are still empty). I just put them back and everything compiles/works like it should.
Don't be tempted to delete those two
Is it possible that it's your test target that can't find the frameworks? You'll have to add the parent location of the frameworks to the "Frameworks Search Path" section of your unit tests (likely $(SRCROOT)/Carthage/Build/iOS).
Here's a sample project of a Swift framework bundling RealmSwift as a dependency which you might find useful to compare your build settings against: https://static.realm.io/debug/ParentFramework.tgz

Cannot Archive when a library is included in my own iOS custom framework

I created my own iOS framework by following this tutorial, https://code.google.com/p/ios-static-framework/, which uses a static library template and aggregate target with a custom run script to create a framework.
At first it works fine. After including another library in the framework project creates the error when archive or build for device. I think the problem is with some wrong settings for that library. But I just don't know what to try. I have tried setting some sensible Other Linker Flags from https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ld.1.html , but no luck. Can anyone help please ;(
What steps will reproduce the problem?
Follow the tutorial, but change the Aggregate script architecture from armv6 armv7 to armv7 armv7s. Here is the part of the aggregate target script I changed. Everything else is the same.
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
SF_OTHER_PLATFORM=iphonesimulator
SF_ARCHS=i386
else
SF_OTHER_PLATFORM=iphoneos
SF_ARCHS="armv7 armv7s"
fi
Add an external library to the project, here I use libBlocksKit.a.
Build the framework, success.
In another child project. Include my built framework.
Add -ObjC in the app Target > Build Settings > Other Linker Flags
Archive and get error. Building for device (iPhone5) gives error too. But building for simulator seems to work.
What is the error?
This error, basically "ld: warning: directory not found for option ... ld: lto: could not merge in ... symbol multiply defined!".
ld: warning: directory not found for option '-L/Users/hlung/Dropbox/- Notes/stackoverflow/RealFrameworkApp/RealFrameworkApp/External/BlocksKit'
ld: lto: could not merge in /Users/hlung/Library/Developer/Xcode/DerivedData/RealFrameworkTest-evagqzwzyyolhjenkkjbvzibxppf/Build/Products/Debug-iphonesimulator/RealFrameworkTest.framework/RealFrameworkTest(NSObject+BlockObservation.o) because 'Linking globals named 'OBJC_CLASS_$_BKObserver': symbol multiply defined!', using libLTO version 'LLVM version 3.2svn, from Apple Clang 4.2 (build 425.0.28)' for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I archive my child project with only one architecture (like armv7), it works. It shows this error with armv7 armv7s architectures ( $(ARCHS_STANDARD_32_BIT) ).
What version of the product are you using? On what operating system?
OS X 10.8.5, XCode 4.6.3
== Update 1 ==
Posted an issue at the tutorial's code.google.com page Update: 2 weeks no answer.
I found a set of useful suggestions from this answer. Update: Doesn't work
I have created a project so you can run and see for yourself here
Linking against a static library from within a framework can create some interesting challenges... It sounds like you may be linking to BlocksKit from both your framework and your application projects.
You should link in only one of those places. Try removing libBlocksKit.a from the Link Libraries build phase of your framework, but leave it in the other project.
You can do like this:
Click on your project (targets)
Click on Build Settings
Under Library Search Paths, delete the paths
I hope it can help you.

Coreplot installation

I installed Coreplot But not working properly
I followed the steps below
Download Coreplot 9.0
Copy the Downloaded folder and paste in to the Application folder with name CorePlotFramework
Add libCorePlot Cocoatouch.a in to the Xcode
Add QuartzCore frame work
Drag and paste the libCorePlot Cocoatouch.a in to Link Libraries with Binaries
Edit Project settings
Other Linker Flags -->-lxml2 -ObjC
Header Search Paths -->CorePlotFramework
Now it's not working.
Open your apps Target Build Settings, and for Other Linker Flags include this: -ObjC and -all_load
Change your C/C++ Compiler in the project build settings to LLVM GCC 4.2 or LLVM 1.6.

Resources