为什么在构建这个C项目时出现所有这些错误?
我在C编写一些类似的程序作为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;
}
从错误中,它几乎看起来好像你混合目的-C头文件并使用C编译器进行编译。尽管如此,仍然很难说。
您的项目,包括/导入了AppKit标头,这是的ObjectiveC,而不是纯粹的C.
由于你方的来源并没有提到它,我敢打赌,它是预编译的头内进口。检查您的项目的预编译头文件以查找此类条目。它将被命名为您的项目,扩展名为.pch
。您可能想要删除任何ObjectiveC导入。
同时检查您是否在项目中使用了任何ObjectiveC框架。如有疑问,请从项目中删除所有列出的框架。
我似乎无法在文件目录或XCode本身中找到这些东西。它可能在哪里? http://imageshack.us/photo/my-images/94/screenshot20120313at232.png/ – Chucky 2012-03-13 23:27:25
严重的是,如果您希望某人指引您朝向正确的方向,请将输出复制并粘贴到您的问题中。错误引用的相关代码也会很好。 – 2012-03-13 23:01:52
没有输出,因为它不会编译。不知道它是哪个特定部分的代码,但它是一个小程序,所以我想我会把它粘贴在下面的编辑^^^ – Chucky 2012-03-13 23:03:24
@Chucky布赖恩指的是编译器的错误消息 - 截图不*有用* ,通常认为复制文本消息更好。 – Till 2012-03-13 23:05:42