【问题标题】:Why all these errors when building this C project?为什么在构建这个 C 项目时会出现所有这些错误?
【发布时间】:2012-03-30 09:54:03
【问题描述】:

作为 XCode 项目的一部分,我正在用 C 编写一些类似的程序。由于这个新程序需要展示一些与第一次工作迭代略有不同的功能,我认为目标是最好的使用方法。

所以我尝试创建一个新目标,并按照我认为正确的方式进行操作,从谷歌搜索如何(在 XCode 中)。但是在编译时,我得到了太多的错误。

这是我得到的错误屏幕:

我发现它存在大量不同字符的问题,所以我确定这可能是一个简单的问题,例如一些丢失的文件。但我不知道该谷歌什么,所以我希望我问的没问题。

在相关的说明中,有人知道为什么我的第一个版本的程序 main.c 不需要像上面那样包含头文件吗?

谢谢!

编辑: 下面是来自新目标的代码,它实际上与迄今为止未更改的程序的第一个版本相同:

/*
 *  ScalarProduct.c
 *  Concurrency_Practical1
 *
 *  Created by Chucky on 11/03/2012.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "ScalarProduct.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

//the final answer
int finalScalarProd;

//random variable
int rand_seed=10;

int rand()
{
    int n;
    n = random()%11;
    //printf("%d\n", n);
    return(n);
}

void* getScalarProduct(void *arg)
{
    //index for loop
    int i;

    //scalarProduct of 10 integers
    int * scalarProd = (int *) arg;

    //my two arrays
    int list1[10];
    int list2[10];

    for (i=0; i<10; i++) {
        list1[i] = rand();
        list2[i] = rand();
        *scalarProd += list1[i]*list2[i];
        printf("%d:\t\t %d\t\t %d\t\t %d\t\t\n", i, list1[i], list2[i], list1[i]*list2[i]);
    }
    return((void*)scalarProd);
}

int main (int argc, const char * argv[]) {
    // insert code here...

    pthread_t t1, t2;
    int sp1= 0, sp2 = 0;

    printf("Index\t List1\t List2\t Product\n\n");

    pthread_create( &t1, NULL, getScalarProduct, &sp1);
    pthread_create( &t2, NULL, getScalarProduct, &sp2);
    pthread_join( t1, NULL);
    pthread_join( t2, NULL);

    printf("\nScalar Products: %d %d\n", sp1, sp2);
    finalScalarProd = sp1 + sp2;


    printf("Result: %d\n", finalScalarProd);

    return 0;
}

【问题讨论】:

  • 说真的,如果您希望有人指出正确的方向,请将输出复制并粘贴到您的问题中。错误引用的相关代码也很好。
  • 没有输出,因为它甚至不会编译。不知道它是代码的哪个特定部分,但它是一个小程序,所以我想我会把它全部粘贴到下面的编辑中^^^
  • @Chucky Brian 指的是编译器的错误消息 - 屏幕截图没有帮助,通常认为复制文本消息会更好。跨度>
  • 我的意思是你发布的截图的输出。我怀疑如果您单击错误旁边的那些小箭头,它们会告诉您问题出在哪里。您缺少 ; 右括号,或其他一些导致混乱的简单语法错误(它是级联的)。
  • 这个我也加一下,虽然很长

标签: c xcode build compilation header


【解决方案1】:

从错误来看,您似乎在混合 Objective-C 头文件并使用 C 编译器进行编译。不过还是很难说。

【讨论】:

    【解决方案2】:

    您的项目正在包含/导入 AppKit-Header,它是 ObjectiveC 而不是纯 C。

    由于您引用的来源没有提到它,我敢打赌它是在预编译的标头中导入的。检查项目的预编译头文件中是否有此类条目。它将像您的项目一样命名,扩展名为.pch。您可能想要删除任何 ObjectiveC 导入。

    还要检查您是否在项目中使用了任何 ObjectiveC 框架。如有疑问,请从您的项目中删除所有列出的框架。

    【讨论】:

    猜你喜欢
    • 2019-05-18
    • 2019-09-17
    • 2013-12-30
    • 2021-05-21
    • 2020-07-27
    • 2022-10-13
    • 1970-01-01
    • 2022-06-22
    • 2023-04-04
    相关资源
    最近更新 更多