Qt + cocoa:架构 x86_64 的未定义符号

Posted

技术标签:

【中文标题】Qt + cocoa:架构 x86_64 的未定义符号【英文标题】:Qt + cocoa : Undefined symbols for architecture x86_64 【发布时间】:2013-03-26 11:37:12 【问题描述】:

我在 Qt 中结合 cocoa 代码,不幸的是出现了未找到符号的错误。 我正在使用 MAC OSX 10.8.2 和 Qt Creator 来构建我的代码。

appcontroller.h

#ifndef APPCONTROLLER_H
#define APPCONTROLLER_H

// Import the Cocoa and ImageCaptureCore headers
#include <Cocoa/Cocoa.h>
#include <ImageCaptureCore/ImageCaptureCore.h>

// Create a public interface for the controller
@interface appController : NSObject

// Create delegates for the device browser and camera device classes.
<ICDeviceBrowserDelegate, ICCameraDeviceDelegate> 

// Create an instance variable for the device browser
// and an array for the cameras the browser finds
ICDeviceBrowser * mDeviceBrowser;
NSMutableArray * mCameras;

// Define Interface Builder outlets for two
// array controllers -- one for cameras,
// one for the chosen camera's files
IBOutlet NSArrayController * mCamerasController;
IBOutlet NSArrayController * mMediaFilesController;

// Define IB outlets for the tableviews used to
// display the cameras and the chosen camera's contents
IBOutlet NSTableView * mCameraContentTableView;
IBOutlet NSTableView * mCamerasTableView;


// Cameras are properties of the device browser stored in an array
@property(retain) NSMutableArray* cameras;

// Create a boolean to indicate whether the camera has images to download
@property(readonly) BOOL canDownload;
@end


#endif // APPCONTROLLER_H

要复制到剪贴板,请将视图切换到纯文本模式

appcontroller.mm

#include "appcontroller.h"

// The camera device returns core graphics image refs,
// convert them to NSImages for table view
@interface NSImageFromCGImageRef: NSValueTransformer 
@end
@implementation NSImageFromCGImageRef
+ (Class)transformedValueClass  return [NSImage class]; 
+ (BOOL)allowsReverseTransformation  return NO; 
- (id)transformedValue:(id)item

if ( item )
return [[[NSImage alloc] initWithCGImage:(CGImageRef)item size:NSZeroSize] autorelease];
else
return nil;
 @end
@implementation appController

// synthesize the getters and setters for camera properties
@synthesize cameras = mCameras;

// Main task -- on launch
- (void)applicationDidFinishLaunching:(NSNotification*)notification

mCameras = [[NSMutableArray alloc] initWithCapacity:0];

// Get an instance of ICDeviceBrowser
mDeviceBrowser = [[ICDeviceBrowser alloc] init];
// Assign a delegate
mDeviceBrowser.delegate = self;
// Look for cameras in all available locations
mDeviceBrowser.browsedDeviceTypeMask = mDeviceBrowser.browsedDeviceTypeMask
| ICDeviceTypeMaskCamera
| ICDeviceLocationTypeMaskLocal
| ICDeviceLocationTypeMaskShared
| ICDeviceLocationTypeMaskBonjour
| ICDeviceLocationTypeMaskBluetooth
| ICDeviceLocationTypeMaskRemote;
// Start browsing for cameras
[mDeviceBrowser start];



// Stop browser and release it when done
- (void)applicationWillTerminate:(NSNotification*)notification 
mDeviceBrowser.delegate = NULL;
[mDeviceBrowser stop];
[mDeviceBrowser release];
[mCameras release];


// Method delegates for device added and removed
//
// Device browser maintains list of cameras as key-value pairs, so delegate
// must call willChangeValueForKey to modify list
- (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing

if ( addedDevice.type & ICDeviceTypeCamera )

addedDevice.delegate = self;

// implement manual observer notification for the cameras property
[self willChangeValueForKey:@"cameras"];
[mCameras addObject:addedDevice];
[self didChangeValueForKey:@"cameras"];




- (void)deviceBrowser:(ICDeviceBrowser*)browser didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing

device.delegate = NULL;

// implement manual observer notification for the cameras property
[self willChangeValueForKey:@"cameras"];
[mCameras removeObject:device];
[self didChangeValueForKey:@"cameras"];


- (void)didRemoveDevice:(ICDevice*)removedDevice

[mCamerasController removeObject:removedDevice];


// Check to see if the camera has image files to download
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context

if ( [keyPath isEqualToString:@"selectedObjects"] && (object == mMediaFilesController) )

[self willChangeValueForKey:@"canDownload"];
[self didChangeValueForKey:@"canDownload"];



- (BOOL)canDownload

if ( [[mMediaFilesController selectedObjects] count] )
return YES;
else
return NO;


// Download images
// (Add a download button in interface builder -- use boolean to enable button)
- (void)downloadFiles:(NSArray*)files

NSDictionary* options = [NSDictionary dictionaryWithObject:[NSURL fileURLWithPath:[@"~/Pictures" stringByExpandingTildeInPath]] forKey:ICDownloadsDirectoryURL];

for ( ICCameraFile* f in files )

[f.device requestDownloadFile:f options:options downloadDelegate:self didDownloadSelector:@selector(didDownloadFile:error:options:contextInfo:) contextInfo:NULL];



// Done downloading -- log results to console for debugging
- (void)didDownloadFile:(ICCameraFile*)file error:(NSError*)error options:(NSDictionary*)options contextInfo:(void*)contextInfo

NSLog( @"didDownloadFile called with:\n" );
NSLog( @" file: %@\n", file );
NSLog( @" error: %@\n", error );
NSLog( @" options: %@\n", options );
NSLog( @" contextInfo: %p\n", contextInfo );

@end

要复制到剪贴板,请将视图切换到纯文本模式

和 ObjectiveC-Integrate.pro

QT += core gui multimedia

TARGET = ObjectiveC-Integrate
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui

CONFIG -= app_bundle
CONFIG += x86_64
CONFIG -= i386
LIBS += -lssl -lcrypto
LIBS += -framework AppKit

OBJECTIVE_HEADERS += \
appcontroller.h

OBJECTIVE_SOURCES += \
appcontroller.mm

要复制到剪贴板,请将视图切换到纯文本模式 在谷歌上进行大量搜索并查看其他帖子后,我无法在我的机器上构建我的代码。 当我在 main.cpp 中包含上述 COCOA 标头时,就会出现数千个错误(@stray)..

【问题讨论】:

【参考方案1】:

您不能在 C++ 文件 (main.cpp) 中包含 Objective C 头文件 (appcontroller.h)。 C++ 不理解 Objective C。

您需要使用此答案中给出的方法之一:Calling Objective-C method from C++ method?

【讨论】:

以上是关于Qt + cocoa:架构 x86_64 的未定义符号的主要内容,如果未能解决你的问题,请参考以下文章

架构 x86_64 的未定义符号将 QT 与 Opencv 结合使用

QT-creator 中架构 x86_64 的未定义符号

架构 x86_64 / i386 的未定义符号

Quickblox:架构 x86_64 的未定义符号:错误

GoogleMapsSDK:架构 x86_64 的未定义符号

Cordova - 架构 x86_64 的未定义符号