Changing source file extension from .m to .mm failing in Xcode 9.3 for Screen Saver project

时间:2018-06-04 17:28:00

标签: c++ objective-c xcode objective-c++ screensaver

Today I decided I wanted to code up a Screen Saver using Xcode for my mac and wanted to do most of the heavy lifting in C++. From my previous experience mixing C++ and Objective-C++, you just need to change the extension of the .m source files to .mm when you want to incorporate some C++ in there.

I am running into an annoying issue, however. If I make an Xcode Screen Saver project and do nothing but rename the initial TestScreenSaverView.m file to TestScreenSaverView.mm, the Screen Saver goes from compiling and linking fine to compiling and having trouble linking. Note that other than changing the extension of the files, I have not added any new code. Here is the log output:

Showing Recent Issues
Check dependencies

Write auxiliary files

write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver.hmap
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-generated-files.hmap
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-all-target-headers.hmap
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-own-target-headers.hmap
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-project-headers.hmap
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-all-non-framework-target-headers.hmap
/bin/mkdir -p /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64
write-file /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaver.LinkFileList

Create product structure

/bin/mkdir -p /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents
/bin/mkdir -p /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents/MacOS

ProcessInfoPlistFile /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents/Info.plist TestScreensaver/Info.plist
    cd /Users/cjh/Documents/code/swift/TestScreensaver
    builtin-infoPlistUtility /Users/cjh/Documents/code/swift/TestScreensaver/TestScreensaver/Info.plist -expandbuildsettings -platform macosx -o /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents/Info.plist

CompileC /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaverView.o TestScreensaver/TestScreensaverView.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/cjh/Documents/code/swift/TestScreensaver
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++14 -stdlib=libc++ -fobjc-arc -fobjc-weak -fmodules -gmodules -fmodules-cache-path=/Users/cjh/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/cjh/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -Wno-c++11-extensions -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.13 -g -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wunguarded-availability -index-store-path /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Index/DataStore -iquote /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-generated-files.hmap -I/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-own-target-headers.hmap -I/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-all-target-headers.hmap -iquote /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/TestScreensaver-project-headers.hmap -I/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/include -I/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/DerivedSources/x86_64 -I/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/DerivedSources -F/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug -MMD -MT dependencies -MF /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaverView.d --serialize-diagnostics /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaverView.dia -c /Users/cjh/Documents/code/swift/TestScreensaver/TestScreensaver/TestScreensaverView.mm -o /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaverView.o

Ld /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents/MacOS/TestScreensaver normal x86_64
    cd /Users/cjh/Documents/code/swift/TestScreensaver
    export MACOSX_DEPLOYMENT_TARGET=10.13
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug -F/Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug -filelist /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaver.LinkFileList -mmacosx-version-min=10.13 -Xlinker -object_path_lto -Xlinker /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaver_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -fobjc-arc -fobjc-link-runtime -ObjC -lc++ -Xlinker -dependency_info -Xlinker /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Intermediates.noindex/TestScreensaver.build/Debug/TestScreensaver.build/Objects-normal/x86_64/TestScreensaver_dependency_info.dat -o /Users/cjh/Library/Developer/Xcode/DerivedData/TestScreensaver-dufowvmnhdeakfekvozrelyhhccq/Build/Products/Debug/TestScreensaver.saver/Contents/MacOS/TestScreensaver

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_ScreenSaverView", referenced from:
      _OBJC_CLASS_$_TestScreensaverView in TestScreensaverView.o
  "_OBJC_METACLASS_$_ScreenSaverView", referenced from:
      _OBJC_METACLASS_$_TestScreensaverView in TestScreensaverView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)



Activity Log Complete    6/4/18, 2:06 PM

Not really sure what the issue is because I have never had issues before. Does anyone have a clue what might be the problem?

For completeness, below is the code that the project initializes with:

TestScreensaverView.h

//
//  TestScreensaverView.h
//  TestScreensaver
//
//  Created by C. Howard on 6/4/18.
//  Copyright © 2018 C. Howard. All rights reserved.
//

#import <ScreenSaver/ScreenSaver.h>

@interface TestScreensaverView : ScreenSaverView

@end

TestScreensaverView.mm (originally TestScreensaverView.m)

//
//  TestScreensaverView.m
//  TestScreensaver
//
//  Created by C. Howard on 6/4/18.
//  Copyright © 2018 C. Howard. All rights reserved.
//

#import "TestScreensaverView.h"

@implementation TestScreensaverView

- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
    self = [super initWithFrame:frame isPreview:isPreview];
    if (self) {
        [self setAnimationTimeInterval:1/30.0];
    }
    return self;
}

- (void)startAnimation
{
    [super startAnimation];
}

- (void)stopAnimation
{
    [super stopAnimation];
}

- (void)drawRect:(NSRect)rect
{
    [super drawRect:rect];
}

- (void)animateOneFrame
{
    return;
}

- (BOOL)hasConfigureSheet
{
    return NO;
}

- (NSWindow*)configureSheet
{
    return nil;
}

@end

1 个答案:

答案 0 :(得分:0)

从错误消息中可以看出,Obj-C类ScreenSaverView的实现似乎缺失了。我没有在ld的命令行中看到它,但是因为你发布了截图而不是从日志中复制粘贴,我无法搜索它,所以也许我错过了它

编辑 Hokay,我自己错过了这一点并且对OP一直很粗鲁,我现在已经到了底层并且它已经到了底层。很简单。

您似乎需要将ScreenSaverView框架添加到项目中,您可以按照此处的方法执行此操作:

http://docs.onemobilesdk.aol.com/ios-ad-sdk/adding-frameworks-xcode.html

如果您的源文件构建为.m不明确,为什么不需要这样做。你认为你总是需要它,但显然不是。把它归结为史蒂夫乔布斯的精神,只是在坟墓之外与我们一起玩弄凡人。