Apple Mach-O Linker Error when using Google Maps S

2020-02-15 03:12发布

问题:

I am trying to use the Google Maps SDK in my app. So far, I have linked all the frameworks. I am pretty sure I have added the appropriate -ObjC flags as per the instructions. However, when I copied and pasted their code into my ViewController.m class, I get the following errors:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_GMSCameraPosition", referenced from: objc-class-ref in FoothillTourViewController.o "_OBJC_CLASS_$_GMSMapView", referenced from: objc-class-ref in FoothillTourViewController.o "_OBJC_CLASS_$_GMSMarker", referenced from: objc-class-ref in FoothillTourViewController.o "_OBJC_CLASS_$_GMSServices", referenced from: objc-class-ref in FoothillTourAppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

"FoothillTourViewController" is the name of my ViewController class. Here is the code for my View Controller class. The code is taken straight from the instructions.

#import "FoothillTourViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation FoothillTourViewController {
    GMSMapView *mapView_;
}

// You don't need to modify the default initWithNibName:bundle: method.

  - (void)loadView {
  //Create a GMSCameraPosition that tells the map to display the
  // coordinate -33.86,151.20 at zoom level 6.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
 mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
 mapView_.myLocationEnabled = YES;
 self.view = mapView_;

  // Creates a marker in the center of the map.
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
  marker.title = @"Sydney";
  marker.snippet = @"Australia";
  marker.map = mapView_;
  }

Any help would be greatly appreciated as I have been spending hours trying to figure out what is happening. I'm guessing its a stupid mistake, but I can't put my finger on it. Thanks!

回答1:

UPDATE: this answer is outdated. The documentation now tells you to use CocoaPods instead of manually linking dependencies.

For more information, see Google Developers Console.

OLD ANSWER:

The Google Maps SDK requires you to link quite a few frameworks. Here they are:

  • AVFoundation.framework
  • CoreData.framework
  • CoreLocation.framework
  • CoreText.framework
  • GLKit.framework
  • ImageIO.framework
  • libc++.dylib
  • libicucore.dylib
  • libz.dylib
  • OpenGLES.framework
  • QuartzCore.framework
  • SystemConfiguration.framework

I found this list at here.



回答2:

Versions 1.9.2 and earlier of the Google Maps SDK for iOS were available as a zip file containing a static framework. There was also the option to install recent versions from a CocoaPods pod. From version 1.10.0 onwards, the Google Maps SDK for iOS is available for installation only via CocoaPods.



回答3:

As you said, you're using the Google Maps SDK for iOS. Yet, it looks like you are compiling for OS X, as the symbols are undefined for i386, an Intel processor. (Unless you are trying to compile for the simulator)

The SDK may not be compiled for the simulator. You can check by running the SDK binary through the "file" command. If it has support for ARM processors, but not i386, it doesn't have support for the simulator. You'll have to change your build flags to only compile for armv7/armv7s processors.