如何将main.c链接到Xcode项目中不同目录下的另一个C文件中

问题描述 投票:0回答:1

在Xcode项目中,语言为C。

    • heap_sort.c
    • heap_sort.c
  • main.c

这是heap_sort.c文件。

#include "heap_sort.h"

int sum(int a, int b)
{
    return a + b;

}

这是heap_sort.h文件。

#ifndef heap_sort_h
#define heap_sort_h

#include <stdio.h>

#endif /* heap_sort_h */

这是我在Xcode中的代码截图。我只是想导入一个函数名 金额 到我的main.c文件。

这是main.c文件

#include <stdio.h>
#include "heap/heap_sort.h"


int main(int argc, const char * argv[]) {
    int s;
    s = sum(3,5);
    printf("The integer is: %d\n",s);
    return 0;
}
c
1个回答
0
投票

你的主文件中没有声明为 sum所以它不知道如何正确调用它。

这个声明应该放在你的头文件中。

#ifndef heap_sort_h
#define heap_sort_h

int sum(int a, int b);

#endif /* heap_sort_h */
© www.soinside.com 2019 - 2024. All rights reserved.