Coder Social home page Coder Social logo

redland-objc's Introduction

Redland Objective-C Wrapper

This projects is a resurrection of Rene Puls' Objective-C wrapper for the Redland C RDF libraries for Mac, with the addition of a static library target suitable for iOS. The code now requires Automatic Reference Counting (ARC) to be enabled.

The wrapped libraries are:

  • raptor2 2.0.13
  • rasqal 0.9.32
  • redland 1.0.17

The documentation is available at http://p2.github.io/Redland-ObjC/. Please note that there will be compilation errors if the path to your project directory contains spaces.

Getting the Framework

If you're using Git for version control of your project (and I hope you are), it's easiest to add the framework as a submodule:

$ cd YourProject
$ git submodule add git://github.com/p2/Redland-ObjC.git
$ git submodule update --init --recursive

If not you should still use Git to check out the latest version:

$ cd YourProject
$ git clone git://github.com/p2/Redland-ObjC.git

Now whenever there has been an update to the framework and you want to get the latest and greatest, you can just pull:

$ cd YourProject/Redland-ObjC
$ git pull

Note that building the C libraries is not possible if your project directory contains spaces. The build script will warn you about this fact and exit.

Building the C libraries

TL;DR: Run the script Redland-source/build.sh

Note: When building the C libraries with Xcode, the progress bar will appear stalled while saying Running 1 of 1 custom shell scripts, which can take some minutes. Just be patient, the compilation will go through or abort with an error.

The first time you build the framework, the C libraries will automatically be built, so you need not worry about this. Compilation requires pkg-config, which will be installed for you if you run the build.sh script. You can install it yourself via Homebrew:

$ brew install pkg-config

Cross compiling librdf

There is a Python-script that downloads and (cross-)compiles raptor2, rasqal and librdf, the components you need. The script needs you to have Xcode 4.5 and the iOS SDK 5.1 or later installed. If you are on Xcode < 5.0, make sure you have the command line tools installed, you do that from within Xcode » Preferences » Downloads » Components.

Just choose the Redland C Library target and hit Run. Alternatively, open the Terminal and execute the script manually:

$ cd Redland-ObjC/Redland-source
$ python cross-compile.py

This will build libraries for armv7, armv7s, arm64, i386 and x86_64. You can change all this in the file cross-compile-config.py if you dare. The script will only build the missing C libraries, if you want to force a new build run the target Redland PURGE C Library or run the script Redland-source/start-over.sh.

Problems? Take a look at common errors.

Using the Framework

The framework is intended to be added to your Xcode workspace and linked into your app. Add the project file Redland.xcodeproj to your own project workspace by dragging it to the file area in Xcode.

Then, in your app's Build Settings, you need to adjust a few things:

For iOS Apps

In your app's Build Phases under Link Binary with Libraries, add these libraries by clicking the [+] button:

  • libredland-ios.a

    Note: After you've added this lib and build your app, Xcode will automatically build the Redland-ObjC project first. As noted above, this will take a few minutes the first time it happens because Xcode cross-compiles the redland C libraries for the first time.

    Note: Xcode seems to have issues when header files get added during a build process, which is what happens on the first cross compile. If your app build fails because of missing headers, simply close and reopen the project again.

  • libxml2.dylib

  • libxslt.dylib

  • libsqlite3.dylib (if you use storage)

Now you need to give Xcode some more hints so it can compile your app

Add this path to your Header Search Paths and User Header Search Paths:

"$(PROJECT_DIR)" with recursive enabled.

This assumes that the Redland-ObjC directory is inside your app directory, adjust as needed.

Add this to Other Linker Flags:

-ObjC

This makes sure categories used in the framework are being correctly loaded. If you forget this flag, your app will crash as soon as you try to use a class method on a Redland object.

A Note on Header Files

What you would usually do with static libraries is have public header files. This however prevents Xcode from building an executable app when archiving since it also archives the public headers to a usr/include folder in the archive.

For this reason all iOS header files in the framework are on project level only. This is why you must tell Xcode to go look for your header files in the project directory instead, as instructed above.

Using Redland Objects

In whichever class you use the Redland-ObjC objects, you need to include our header:

#import <Redland-ObjC.h>

Here's an example on how you would parse RDF+XML contained in a file example.xml in your bundle:

NSString *rdfPath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"xml"];
NSString *rdfString = [[NSString alloc] initWithContentsOfFile:rdfPath
                                                      encoding:NSUTF8StringEncoding
                                                         error:nil];
RedlandParser *parser = [RedlandParser parserWithName:RedlandRDFXMLParserName];
RedlandURI *uri = [RedlandURI URIWithString:@"http://www.w3.org/1999/02/22-rdf-syntax-ns#"];
RedlandModel *model = [RedlandModel new];

// parse
@try {
	[parser parseString:rdfString intoModel:model withBaseURI:uri];
}
@catch (NSException *exception) {
	NSLog(@"Failed to parse RDF: %@", [exception reason]);
}

example.xml:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
  <rdf:Description rdf:about="http://www.w3.org/2001/08/rdf-test/">
    <dc:creator>Jan Grant</dc:creator>
    <dc:creator>Dave Beckett</dc:creator>
    <dc:publisher>
      <rdf:Description>
        <dc:title>World Wide Web Consortium</dc:title>
        <dc:source rdf:resource="http://www.w3.org/"/>
      </rdf:Description>
    </dc:publisher>
  </rdf:Description>
</rdf:RDF>

Here's how you would query this model for one of the creators of rdf-test:

RedlandNode *subject = [RedlandNode nodeWithURIString:@"http://www.w3.org/2001/08/rdf-test/"];
RedlandNode *predicate = [RedlandNode nodeWithURIString:@"http://purl.org/dc/elements/1.1/creator"];
RedlandStatement *statement = [RedlandStatement statementWithSubject:subject
                                                           predicate:predicate
                                                              object:nil];
RedlandStreamEnumerator *query = [model enumeratorOfStatementsLike:statement];

RedlandStatement *rslt = [query nextObject];
// be aware that if literalValue can only be used on literal nodes.
// object is the object-node of the RedlandStatement that is returned by the query.
NSString *creator = [rslt.object literalValue];
NSLog(@"Creator: %@", creator);

I've made a simple demo app for iOS if you want to see it in action. The demo app contains the framework as a submodule, so just clone the demo repository and hit Run.

Building the Documentation

The code is documented using appledoc and available on http://p2.github.io/Redland-ObjC/. Appledoc allows you to integrate the documentation right into Xcode, meaning you can then ALT - click Redland classes and methods to see what they do.
If you want to compile the documentation, it's best if you grab appledoc from GitHub directly:

$ git clone git://github.com/tomaz/appledoc.git
$ cd appledoc
$ ./install-appledoc.sh -b /usr/local/bin -t ~/Library/Application\ Support/appledoc

Note that this assumes that you have write permissions for /usr/local, if not you may need to issue this command as root with sudo.

Afterwards just select the Redland Documentation target in Xcode and hit CMD + B. This will build and install the documentation, after which it will be available from within Xcode. To build manually you do:

$ appledoc .

NOTE: appledoc currently does not support the ///< token, so some property documentations are shifted and thus off!

redland-objc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redland-objc's Issues

Stepping into redland c libs during xCode debugging

I'm trying to step into the redland c functions from the wrapper classes in Xcode.

At the moment the debugger just skips to the next Objective-c statement.

Is there a straight forward way to configure the project for debugging into the underlying libraries?

Andy

sqlite storage

currently sqlite isn't available for storage - despite the linked sqlite library indicating such.

To achieve this, it seems to take a couple of steps:

  1. add --with-sqlite=3 to Redland-source/cross-compile-config.py,
  2. patch Redland-source/*/pp-configure.sh to hand on a previously set PKG_CONFIG_PATH,
  3. $ brew install sqlite,
  4. $ export PKG_CONFIG_PATH=/usr/local/Cellar/sqlite/*/lib/pkgconfig/,
  5. check $ grep "Triple stores enabled" Redland-source/build-*/redland-*/config.log to contain sqlite,
  6. use a RedlandStorage *storage = [[RedlandStorage alloc] initWithFactoryName:@"sqlite" identifier:@"foo.sqlite" options:@"new='yes'"];,
  7. the above filename foo.sqlite may have to be an absolute path into e.g. the Documents directory,
  8. what else?

Building Redland C libraries in Xcode 5 fails in "Configuring build-iOS-armv7/libxml2-2.7.8"

I am running into two problems when following instructions towards install Redland-ObjC as submodule into my iOS app project (one trivial and one blocking):

  1. The project's path in the file system contained spaces. Apparently that won't do because of autoconf restrictions. It may be worthwhile mentioning this in the instructions.
  2. When I build Redland C libraries (either inside Xcode or by cross-compile.py on command line) this fails in the Configuring build-iOS-armv7/libxml2-2.7.8 step. Judging from config.log a script apparently makes wrong assumptions about the location of the cross compiler:
configure:2992: checking for arm-apple-darwin-gcc
configure:3019: result: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc

Perhaps this needs updating for Xcode 5 (xcrun --sdk might help).

Here's what I use: OS X 10.9, Xcode 5.0.2 with command line tools (FWIK), pkg-config from brew.

Question re use of RedlandNamespace

Great framework, I am using it in an iOS project.

I have a question regarding the correct use of RedlandNamespace, this is probably a lack of understanding on my behalf of redland itself.

I can execute SPARQL queries directly without registering RedlandNamespace instances, like:

PREFIX foaf: http://xmlns.com/foaf/0.1/
SELECT ?x ?name
WHERE {
?x foaf:name ?name
}

So when would I need to create and register RedlandNamespace instances?

Andy

Linking fails for simulator: "Undefined symbols for architecture i386 ... _xsltApplyStylesheetUser"

I am using the latest code base for Redland-ObjC in an Xcode 5 project on OS X 10.9 following setup instructions in README.md. cross-compile.py succeeds, i.e. it compiles raptor / rasqal / redland also for Sim: i386.

If I build the project for running on a device, this succeeds. However, if try building it for running on an iOS device simulator, this fails with the following error (excerpt):

Undefined symbols for architecture i386:
  "_xsltApplyStylesheetUser", referenced from:
      _raptor_grddl_run_grddl_transform_doc in libredland-ios.a(raptor_grddl.o)
  "_xsltCleanupGlobals", referenced from:
      _raptor_terminate_parser_grddl_common in libredland-ios.a(raptor_grddl.o)

Is this a matter of the linker not picking up (the correct version of) libxslt from OS X? Am I supposed to do anything special here?

cross-compile.py cannot pick up libxslt.dylib for armv7 architecture

This is a follow-up issue to #4.

The compilation now fails because it apparently tries to pick up e.g. libxml2.dylib from a wrong location. Here's the peraps relevant excerpt of cross-compile.py's output:

-> libxml2-sources-2.7.8.tar.gz
--> Downloading libxml2-sources-2.7.8.tar.gz (3472 KB)
3472005 [100.00%]

--> iOS: armv7
---> Unpacking downloads/libxml2-sources-2.7.8.tar.gz
---> Configuring build-iOS-armv7/libxml2-2.7.8
---> Building build-iOS-armv7/libxml2-2.7.8
---> Installing build-iOS-armv7/libxml2-2.7.8

/bin/sh ../libtool --tag=CC --mode=link /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=c99 -arch armv7 -pipe --sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' -isysroot '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/include -I/PATH_WITHOUT_SPACES/Redland-ObjC/Redland-source/product-iOS-armv7/include --sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' -isysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib -L/PATH_WITHOUT_SPACES/Redland-ObjC/Redland-source/product-iOS-armv7/lib -o rapper rapper.o ../src/libraptor2.la
libtool: link: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=c99 -arch armv7 -pipe --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/include -I/PATH_WITHOUT_SPACES/Redland-ObjC/Redland-source/product-iOS-armv7/include --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -isysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -o rapper rapper.o -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib -L/PATH_WITHOUT_SPACES/Redland-ObjC/Redland-source/product-iOS-armv7/lib ../src/.libs/libraptor2.a -L/opt/local/lib /opt/local/lib/libxslt.dylib /opt/local/lib/libxml2.dylib /opt/local/lib/liblzma.dylib -lz -lpthread /opt/local/lib/libiconv.dylib -lm -pthread
ld: warning: ignoring file /opt/local/lib/libxslt.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (armv7): /opt/local/lib/libxslt.dylib
ld: warning: ignoring file /opt/local/lib/libxml2.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (armv7): /opt/local/lib/libxml2.dylib
ld: warning: ignoring file /opt/local/lib/liblzma.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (armv7): /opt/local/lib/liblzma.dylib
ld: warning: ignoring file /opt/local/lib/libiconv.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (armv7): /opt/local/lib/libiconv.dylib
Undefined symbols for architecture armv7:

"_htmlCreatePushParserCtxt", referenced from:
_raptor_grddl_parse_chunk in libraptor2.a(raptor_grddl.o)
"_htmlCtxtUseOptions", referenced from:
_raptor_grddl_parse_chunk in libraptor2.a(raptor_grddl.o)
"_htmlFreeParserCtxt", referenced from:
_raptor_grddl_parse_terminate in libraptor2.a(raptor_grddl.o)
_raptor_grddl_parse_chunk in libraptor2.a(raptor_grddl.o)
"_htmlParseChunk", referenced from:
_raptor_grddl_parse_chunk in libraptor2.a(raptor_grddl.o)
"_xmlAddChildList", referenced from:
_raptor_libxml_getEntity in libraptor2.a(raptor_libxml.o)
"_xmlCleanupParser", referenced from:
_raptor_libxml_finish in libraptor2.a(raptor_libxml.o)
"_xmlCreatePushParserCtxt", referenced from:
_raptor_grddl_uri_xml_parse_bytes in libraptor2.a(raptor_grddl.o)
_raptor_grddl_parse_chunk in libraptor2.a(raptor_grddl.o)
_raptor_sax2_parse_chunk in libraptor2.a(raptor_sax2.o)

ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
make[1]: *** [rapper] Error 1
make: *** [all-recursive] Error 1

I am wondering: why is ld not instructed to pick up libxml2.dylib from where it was placed by the previous compile step and where that would be. At /opt/local/lib/libxml2.dylib is apparently an older version (perhaps part of OS X or installed by MacPorts) for the x86_64 (not armv7) architecture.

BTW, if I run cd /PATH_WITHOUT_SPACES; find . -name lib''.dylib* I get this (i.e. neither libxml2.dylib nor one of the other three libraries exists here for the armv7 architecture).

./Redland-source/build-Mac-i386/libxml2-2.7.8/.libs/libxml2.2.dylib
./Redland-source/build-Mac-i386/libxml2-2.7.8/.libs/libxml2.2.dylib.dSYM/Contents/Resources/DWARF/libxml2.2.dylib
./Redland-source/build-Mac-i386/libxml2-2.7.8/.libs/libxml2.dylib
./Redland-source/build-Mac-i386/raptor2-2.0.9/src/.libs/libraptor2.0.dylib
./Redland-source/build-Mac-i386/raptor2-2.0.9/src/.libs/libraptor2.dylib
./Redland-source/build-Mac-x86_64/libxml2-2.7.8/.libs/libxml2.2.dylib
./Redland-source/build-Mac-x86_64/libxml2-2.7.8/.libs/libxml2.2.dylib.dSYM/Contents/Resources/DWARF/libxml2.2.dylib
./Redland-source/build-Mac-x86_64/libxml2-2.7.8/.libs/libxml2.dylib
./Redland-source/build-Mac-x86_64/raptor2-2.0.9/src/.libs/libraptor2.0.dylib
./Redland-source/build-Mac-x86_64/raptor2-2.0.9/src/.libs/libraptor2.dylib
./Redland-source/product-Mac-i386/lib/libraptor2.0.dylib
./Redland-source/product-Mac-i386/lib/libraptor2.dylib
./Redland-source/product-Mac-i386/lib/libxml2.2.dylib
./Redland-source/product-Mac-i386/lib/libxml2.dylib
./Redland-source/product-Mac-x86_64/lib/libraptor2.0.dylib
./Redland-source/product-Mac-x86_64/lib/libraptor2.dylib
./Redland-source/product-Mac-x86_64/lib/libxml2.2.dylib
./Redland-source/product-Mac-x86_64/lib/libxml2.dylib

cross-compile.py fails apparently when run from inside a directory whose name contains spaces

First and foremost: thanks for your effort on Redland-ObjC!

I am trying to cross-compile Redland iOS libraries for iOS on OS X 10.7.5 (i.e. Lion, not Mointain Lion) and Xcode 4.6.1 by following the instructions in README.md. However, cross-compile.py currently fails.

The directory where I'd like Redland-ObjC to reside as a submodule of my project has a name that contains spaces. If I place the sources inside a directory without such spaces (which is inconvenient for my use case) this immediate problem disappears.

Could you please advise what the exact cause may be and how it can be overcome in a better fashion? Re-thx.

Dependencies and stuff

Hi,
I have been working with this project and iOS the past week, as you've already seen from the PR i sent, and I think I have discovered some problems.

The first is that the example in the readme is incomplete. I have written a more complete example that works, you can see it on my branch. I am however a bit unsure if it a good way to be using the library, so I haven't issued a PR to you with it.

Secondly, the description of how to use it, at least on iOS, is not complete. This might be because of an update in Xcode at some point. What didn't work was to select and pull the *.a files into /Link Binary with Library/, but I had to select the libraries and then on the right side I check off on Target Membership for Redland and redland-ios. I also had to add libsqlite3.0.dylib to my project target (in link binary with..).

Other than that the project seems to work nicely. I have some improvements in mind, but I want to work a little bit more with the project to see if it is just that I am not familiar with it that makes me want to change it :) .

Exception raised if librdf issues warning

I stumbled over this when using unbound variables in queries. Librdf issues a warning which is stored as an error in RedlandWorld:handleLogMessage and causes an exception to be thrown in RedlandWorld:handleStoredErrors. One workaround is to store only messages with LIBRDF_LOG_FATAL and maybe LIBRDF_LOG_ERROR as actual errors.

64 bit arm support

Target for 64-bit arm processors is missing (iPhone 5s, iPad Air, iPad mini retina)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.