views:

1467

answers:

3

I have just added a Core Plot view to my application based on a tutorial (http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application). I have put the Core Plot drawing code in the windowDidLoad method of the window controller for the window where I have included the CPLayerHostingView. The code for the plot is:

CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6) 
              length:CPDecimalFromFloat(12)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5) 
              length:CPDecimalFromFloat(30)];

CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;

CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor blackColor];
lineStyle.lineWidth = 2.0f;

axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];  
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.axisLabelOffset = 3.0f;

axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];  
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.axisLabelOffset = 3.0f;

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] 
        initWithFrame:graph.defaultPlotSpace.bounds] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
xSquaredPlot.dataLineStyle.lineWidth = 1.0f;
xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];
xSquaredPlot.dataSource = self;
[graph addPlot:xSquaredPlot];

When I build I get the following errors:

".objc_class_name_CPPlotRange", referenced from: literal-pointer@__OBJC@__cls_refs@CPPlotRange in HistogramWindowController.o

"_CPDecimalFromFloat", referenced from: -[HistogramWindowController windowDidLoad] in HistogramWindowController.o -[HistogramWindowController windowDidLoad] in HistogramWindowController.o -[HistogramWindowController windowDidLoad] in HistogramWindowController.o -[HistogramWindowController windowDidLoad] in HistogramWindowController.o

".objc_class_name_CPLineStyle", referenced from: literal-pointer@__OBJC@__cls_refs@CPLineStyle in HistogramWindowController.o

".objc_class_name_CPXYGraph", referenced from: literal-pointer@__OBJC@__cls_refs@CPXYGraph in HistogramWindowController.o

".objc_class_name_CPScatterPlot", referenced from: literal-pointer@__OBJC@__cls_refs@CPScatterPlot in HistogramWindowController.o

".objc_class_name_CPPlotSymbol", referenced from: literal-pointer@__OBJC@__cls_refs@CPPlotSymbol in HistogramWindowController.o

".objc_class_name_CPColor", referenced from: literal-pointer@__OBJC@__cls_refs@CPColor in HistogramWindowController.o

".objc_class_name_CPFill", referenced from: literal-pointer@__OBJC@__cls_refs@CPFill in HistogramWindowController.o

ld: symbol(s) not found collect2: ld returned 1 exit status

I've never encountered an error like this. Can anyone shed any light on what the problem might be?

Cheers

+2  A: 

It means you haven't linked in the framework correctly. You've probably just added the framework to your project, #imported the header, but forgot to make sure that the framework is actually getting linked into your target.

Dave DeLong
A: 

You might also check whether your application target is set to include 64-bit support and whether the framework has such support (use the file(1) command for the latter part). If you're building your app with 64-bit support, but try to link against a framework that doesn't have 64-bit support, the linker will throw errors like that when it tries to link the 64-bit portion of your app, while the 32-bit portions will succeed.

Peter Hosey
By default, the framework should be compiling a 32/64-bit Universal target, but you're right that this is something to watch for.
Brad Larson
+1  A: 

There are some instructions on this wiki page for incorporating the framework into Mac projects. If you follow those, you should be able to avoid any problems with linking in the framework.

Brad Larson