Friday, July 29, 2011

Setting up CorePlot in xcode 4

After a few frustrating hours, this is how I set up CorePlot in xcode 4:

Download the latest Core-Plot.zip file here.

We're going to do a Static Library Install:

Make a new View-Based project:
Drag the CorePlot-CocoaTouch.xcodeproj file from the finder into your project base and make sure to check the box to Copy the items into the destination group folder::

Copy the CorePlotHeaders directory to your Xcode project and make sure to check the box to Copy the items into the destination group folder:
Copy the Core Plot library to your Xcode project:
Open your apps Target Build Settings, and for Other Linker Flags include this: -ObjC -all_load
Press the "+" to add the Linker Flag, copy and paste above into the top empty space and press "Done".

Add the QuartzCore framework to the project:
Go to the "Link Binary With Libraries" tab under the "Build Phases" tab. Select the "+" button to add another linked library.
 Search for "quartz" in the search bar to quickly find the needed library then press "Add" (it will appear in your project directory). Drag the QuartzCore.framework library into the Frameworks folder:
Change your C/C++ Compiler in the project build settings to LLVM GCC 4.2 or LLVM 1.6.
In your ViewController.m file add #import "CorePlot-CocoaTouch.h"
Now you're ready to build! 

*Note:
The prefix of all core plot entities has changed from CP to CPT. So if you find a nice tutorial to work from 
that is older, you will get a Cannot find protocol declaration for 'CPPlotDataSource' or similar build error. 
So CPXTGraph needs to be changed to CPTXYGraph.

28 comments:

  1. Thanks a lot ! This step-by-step install process was great. Most of what's online is already outdated so this was much needed!

    ReplyDelete
  2. Hi
    Does core plot support stacked bar charts?

    ReplyDelete
  3. @vani Yes, CorePlot does support stacked bar charts. Check out this link here as someone asked a similar question in the Google Groups discussion:

    http://groups.google.com/group/coreplot-discuss/browse_thread/thread/423ca5278d3824ae/4e47a77a8e55c32c?lnk=gst&q=stacked+bar+chart#4e47a77a8e55c32c

    ReplyDelete
  4. I have some problem when i add "-ObjC -all_load" into Other Linker Flags.The project can be built.

    ReplyDelete
  5. The project can not be buit.What is wrong?

    ReplyDelete
  6. @Anonymous I'm not sure what you are asking. Are you saying that the project cannot be built with the linker flags and can without? I need more information. Thanks.

    ReplyDelete
  7. The project cannot be built with the linker flags "-ObjC -all_load".errors as following:

    ld: duplicate symbol _EstimateBas64DecodedDataSize in /Users/huoyan/Documents/workspace/YunBo14/WeiboEngine/libOAuth.a(Base64Transcoder.o) and /Users/huoyan/Library/Developer/Xcode/DerivedData/YunBo-fzwmdrzjjchwnmciiuynjnlowzoq/Build/Intermediates/YunBo.build/Debug-iphonesimulator/YunBo.build/Objects-normal/i386/Base64Transcoder.o for architecture i386
    collect2: ld returned 1 exit status
    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    ReplyDelete
  8. "/Users/XXX/Documents/CorePlotTest/CorePlotTest/CorePlotTestViewController.m:10:32: error: CorePlot-CocoaTouch.h: No such file or directory"

    Hmm. But I can see CorePlot-CocoaTouch.h sitting in the "Other Sources" folder underneath the CorePlot-CocoaTouch.xcodeproj folder. I thought I followed every step . . . I apologize if this is a stupid question, I'm a Perl scripter . . .

    Xcode 4.1, Lion 10.7

    ReplyDelete
  9. Can't thank you enough for this. Tried a bunch of other tutorials and this one made it work for me. Thanks!

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. I'm getting errors when trying to link the application. I followed the steps above to the letter. Any ideas?

    Ld /Users/andres/Library/Developer/Xcode/DerivedData/testview2-dakiydpyfemikwhdrseeyymzrbbt/Build/Products/Debug-iphoneos/testview.app/testview normal armv7
    cd /Users/andres/bignerdranch/testview
    setenv IPHONEOS_DEPLOYMENT_TARGET 4.3
    setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -L/Users/andres/Library/Developer/Xcode/DerivedData/testview2-dakiydpyfemikwhdrseeyymzrbbt/Build/Products/Debug-iphoneos -L/Users/andres/bignerdranch/testview -F/Users/andres/Library/Developer/Xcode/DerivedData/testview2-dakiydpyfemikwhdrseeyymzrbbt/Build/Products/Debug-iphoneos -filelist /Users/andres/Library/Developer/Xcode/DerivedData/testview2-dakiydpyfemikwhdrseeyymzrbbt/Build/Intermediates/testview.build/Debug-iphoneos/testview.build/Objects-normal/armv7/testview.LinkFileList -dead_strip -ObjC -all_load -miphoneos-version-min=4.3 -framework QuartzCore -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/andres/Library/Developer/Xcode/DerivedData/testview2-dakiydpyfemikwhdrseeyymzrbbt/Build/Products/Debug-iphoneos/testview.app/testview

    Undefined symbols for architecture armv7:
    "_OBJC_CLASS_$_CPTPlotRange", referenced from:
    objc-class-ref in testviewViewController.o
    "_OBJC_CLASS_$_CPTColor", referenced from:
    objc-class-ref in testviewViewController.o
    "_OBJC_CLASS_$_CPTMutableLineStyle", referenced from:
    objc-class-ref in testviewViewController.o
    "_OBJC_CLASS_$_CPTScatterPlot", referenced from:
    objc-class-ref in testviewViewController.o
    "_CPTDecimalFromFloat", referenced from:
    -[testviewViewController viewDidLoad] in testviewViewController.o
    "_OBJC_CLASS_$_CPTFill", referenced from:
    objc-class-ref in testviewViewController.o
    "_OBJC_CLASS_$_CPTXYGraph", referenced from:
    objc-class-ref in testviewViewController.o
    "_OBJC_CLASS_$_CPTPlotSymbol", referenced from:
    objc-class-ref in testviewViewController.o
    ld: symbol(s) not found for architecture a

    ReplyDelete
  12. Thank u so much. was struggling for 2 days for this :)

    ReplyDelete
  13. I want to mention that the best way to get help with this, as in errors, check out the main forum for coreplot on the google groups page. The guys who created this get back to you in less than 24 hours :)

    Sorry if I did not help you. Another thing I did was when I ran into an error I went through these instructions on a new project and see if I ran into the same issue. I still sometimes follow my own tutorial when I run into a jam ;p

    ReplyDelete
  14. @Joe LIn check out your linkers, that seems like a bunch of linker errors. Did you add the linker flags listed above?

    ReplyDelete
  15. I get the same error like @Joe Lln.

    ----------------------------------------------
    Apple Mach-O Linker (ld)Error

    "Undefined symbols for architecture i386:
    ...
    ld:symbol(s) not found
    ----------------------------------------------
    But I've entered the linker flags like above!

    ReplyDelete
    Replies
    1. Did you ever get this solved? What was the solution?

      Delete
    2. The comment above looks like he forgot to add i386 to the Valid Architecture list. I've been noticing that a lot when making projects in Xcode4.

      Delete
  16. Thanks for a great tutorial. I went straight to it today when creating a new CorePlot project, because when I first used CorePlot last year the installation was time-consuming and frustrating. Now installation is easier, partly because I've been through it before, partly because the updated Xcode interface is better organized, and partly because this tutorial was so helpful.

    There may be one slight typographical error. The instructions say, "In your ViewController.m file add #import "CorePlot-CocoaTouch.h""--but I think the instructions should read "In your ViewController.h file...." The picture below this portion of the instructions is of an excerpt from the ViewController.h file.

    The typographical error may be obvious to most readers, especially after contrasting the picture of the ViewController.h file with the code of the ViewController.m file, but it might not be obvious to all. Having added the import code to the ViewController.h file, I was able to build my project successfully on the first try.

    Thanks again!

    -- Tom

    ReplyDelete
  17. Hi,

    I received a build error in main.m:

    "Expected expression before '@' token"

    Here is the code:

    #import

    #import "AppDelegate.h"

    int main(int argc, char *argv[])
    {
    @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
    }

    Any help would be greatly appreciated.

    ReplyDelete
  18. Fantastic tutorial! thanks a million!

    ReplyDelete
  19. Hi,

    "Copy the Core Plot library to your Xcode project:"

    Using static libraries can be a reason for Apple to reject the app at publish ?

    Thanks.

    ReplyDelete
    Replies
    1. No, having static libraries in your app will not be a cause for rejection.

      Delete
  20. It seems you're mixing up two different approaches: adding the static library AND adding CorePlot as a subproject. Am i understanding it correctly?

    ReplyDelete
  21. I definitely added it in as a subproject but I also added the framework to the project so Xcode knows it exists. At least these were the steps I took after hours of frustration. If you find a better way to set this up I'm all ears!

    ReplyDelete
  22. Not the most clear tutorial, but this one finally worked for me. Make sure you look at every picture of this tutorial to make sure you don't miss any unwritten steps.

    ReplyDelete
  23. 'CorePlot-CocoaTouch.h' file not found

    Iam getting the above error. what to do ? Help ?

    ReplyDelete
  24. most beautiful internet site artwork http://casinogamesonlinee.blogspot.com casino games online

    ReplyDelete

Blog Archive