0

我有一个简单的 Xcode 项目,其中包含一个 C++ 类。但是,当我尝试在 Xcode 中构建该项目时,我收到以下错误消息:

error: unable to spawn process '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' (No such file or directory) (in target 'iOSStaticLibrary' from project 'iOSStaticLibrary')

此外,还会发出以下警告:

warning: Could not read serialized diagnostics file: error("Failed to open diagnostics file") (in target 'iOSStaticLibrary' from project 'iOSStaticLibrary')

我不知道如何将实际项目附加到我的帖子中。它仅包含 3 个文件,因此,我将在下面发布相关文件名和内容。

为了重现问题,在指定文件夹中创建3个文件并添加相应的内容。

文件ARM64/Debug/iOSStaticLibrary.xcodeproj/project.pbxproj

// !$*UTF8*$!
{
    archiveVersion = 1;
    classes = {
    };
    objectVersion = 46;
    objects = {

/* Begin PBXBuildFile section */
        3b051b2877334f3891e05fbf /* iOSStaticLibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 810f8ddb516f4fd9aae95391 /* iOSStaticLibrary.cpp */; settings = {COMPILER_FLAGS = "-c -Wall -Wswitch -W\"no-deprecated-declarations\" -W\"empty-body\" -W\"bool-conversion\" -W\"constant-conversion\" -W\"shorten-64-to-32\" -W\"enum-conversion\" -W\"int-conversion\" -W\"return-type\" -Wparentheses -W\"no-pointer-sign\" -W\"no-format\" -Wuninitialized -W\"unreachable-code\" -W\"unused-function\" -W\"unused-value\" -W\"unused-variable\" -O0 -fno-strict-aliasing -fwritable-strings -fno-threadsafe-statics -fno-exceptions -std=gnu++11 -x c++"; }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
        0e5228c6fe3a40ef9446f1d3 /* libiOSStaticLibrary.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libiOSStaticLibrary.a; sourceTree = BUILT_PRODUCTS_DIR; };
        810f8ddb516f4fd9aae95391 /* iOSStaticLibrary.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = iOSStaticLibrary.cpp; path = ../../../iOSStaticLibrary.cpp; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
        c8f1fdfa1a1a4cf2af0a7098 /* Frameworks */ = {
            isa = PBXFrameworksBuildPhase;
            buildActionMask = 2147483647;
            files = (
            );
            runOnlyForDeploymentPostprocessing = 0;
        };
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
        20adea7cddb14f79ab5df50b /* Products */ = {
            isa = PBXGroup;
            children = (
                0e5228c6fe3a40ef9446f1d3 /* libiOSStaticLibrary.a */,
            );
            name = Products;
            sourceTree = SOURCE_ROOT;
        };
        cb87a76375d04d85a8368aa7 = {
            isa = PBXGroup;
            children = (
                810f8ddb516f4fd9aae95391 /* iOSStaticLibrary.cpp */,
                20adea7cddb14f79ab5df50b /* Products */,
            );
            sourceTree = "\"<group>\"";
        };
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
        3488e49fcf514802b7be61b6 /* iOSStaticLibrary */ = {
            isa = PBXNativeTarget;
            buildConfigurationList = 67256f7dc92b42baa13ec8d3 /* Build configuration list for PBXNativeTarget "iOSStaticLibrary" */;
            buildPhases = (
                7baf7bfde3004dd493908ddd /* Sources */,
                c8f1fdfa1a1a4cf2af0a7098 /* Frameworks */,
            );
            buildRules = (
            );
            dependencies = (
            );
            name = iOSStaticLibrary;
            productName = iOSStaticLibrary;
            productReference = 0e5228c6fe3a40ef9446f1d3 /* libiOSStaticLibrary.a */;
            productType = "com.apple.product-type.library.static";
        };
/* End PBXNativeTarget section */

/* Begin PBXProject section */
        ee73158d3505468a8fdc43b9 /* Project object */ = {
            isa = PBXProject;
            attributes = {
                LastUpgradeCheck = 0610;
                ORGANIZATIONNAME = MyOrganizationName;
                TargetAttributes = {
                    3488e49fcf514802b7be61b6 = {
                        CreatedOnToolsVersion = 6.1;
                    };
                };
            };
            buildConfigurationList = 33fd7959eb644d189bbaa7f7 /* Build configuration list for PBXProject "iOSStaticLibrary" */;
            compatibilityVersion = "Xcode 3.2";
            developmentRegion = English;
            hasScannedForEncodings = 0;
            knownRegions = (
                English,
                en,
            );
            mainGroup = cb87a76375d04d85a8368aa7;
            productRefGroup = 20adea7cddb14f79ab5df50b /* Products */;
            projectDirPath = "\n\n        ";
            projectRoot = "\n\n        ";
            targets = (
                3488e49fcf514802b7be61b6 /* iOSStaticLibrary */,
            );
        };
/* End PBXProject section */

/* Begin PBXSourcesBuildPhase section */
        7baf7bfde3004dd493908ddd /* Sources */ = {
            isa = PBXSourcesBuildPhase;
            buildActionMask = 2147483647;
            files = (
                3b051b2877334f3891e05fbf /* iOSStaticLibrary.cpp in Sources */,
            );
            runOnlyForDeploymentPostprocessing = 0;
        };
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
        1cbb1a8c7cbf4c2699369b65 /* Debug */ = {
            isa = XCBuildConfiguration;
            buildSettings = {
            };
            name = Debug;
        };
        fda96981947c4c2cb659f3e3 /* Debug */ = {
            isa = XCBuildConfiguration;
            buildSettings = {
                CLANG_CXX_LIBRARY = "libc++";
                IPHONEOS_DEPLOYMENT_TARGET = 8.1;
                ONLY_ACTIVE_ARCH = YES;
                PRODUCT_NAME = "$(TARGET_NAME)";
                SDKROOT = iphoneos;
                SKIP_INSTALL = YES;
            };
            name = Debug;
        };
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
        33fd7959eb644d189bbaa7f7 /* Build configuration list for PBXProject "iOSStaticLibrary" */ = {
            isa = XCConfigurationList;
            buildConfigurations = (
                1cbb1a8c7cbf4c2699369b65 /* Debug */,
            );
            defaultConfigurationIsVisible = 0;
            defaultConfigurationName = Debug;
        };
        67256f7dc92b42baa13ec8d3 /* Build configuration list for PBXNativeTarget "iOSStaticLibrary" */ = {
            isa = XCConfigurationList;
            buildConfigurations = (
                fda96981947c4c2cb659f3e3 /* Debug */,
            );
            defaultConfigurationIsVisible = 0;
            defaultConfigurationName = Debug;
        };
/* End XCConfigurationList section */
    };
    rootObject = ee73158d3505468a8fdc43b9 /* Project object */;
}

文件iOSStaticLibrary.h

class iOSStaticLibrary
{
public:
    iOSStaticLibrary();
    ~iOSStaticLibrary();
};

文件iOSStaticLibrary.cpp

#include "iOSStaticLibrary.h"

iOSStaticLibrary::iOSStaticLibrary()
{
}

iOSStaticLibrary::~iOSStaticLibrary()
{
}

我的假设是 project.pbxproj 中的某些内容不是应有的。这个文件是由代码生成器生成的,而不是由 Xcode 本身生成的,所以很可能就是这种情况。

但是,对于我的生活,我无法弄清楚出了什么问题。

4

1 回答 1

1

好吧,我发现了问题。代码生成器将 Xcode 项目创建为 XML 文件。如果我在 Xcode 中打开它并对其应用更改,Xcode 会自动将文件转换为其他非 XML 文件格式(即如问题所示)

现在,代码生成器发出以下有问题的代码:

        ...
        <key>projectDirPath</key>
        <string>
        </string>
        ...
        <key>projectRoot</key>
        <string>
        </string>
        ..

两个键 ( projectDirPath/ projectRoot) 都应该有一个空字符串作为值,实际上在上面的 XML 中它看起来确实是空的。

但是,Xcode 对它的解释不同。如果 XML 文件转换为其他格式,则如下所示:

...
projectDirPath = "\n\n        ";
projectRoot = "\n\n        ";
...

因此,Xcode 将 和 之间的空格解释<string></string>实际值。要修复它,必须调整代码生成器以发出

        ...
        <key>projectDirPath</key>
        <string></string>
        ...
        <key>projectRoot</key>
        <string></string>
        ...

<string />或任何其他有效方式代替上述方法。这实际上解决了问题。

于 2020-10-07T17:08:38.527 回答