我正在尝试编译包含头文件到.c文件的ac程序.但只有一个.c文件真正使用头文件中定义的变量.这是一些将生成链接器问题的示例代码.我试图让我的头文件包含由2个不同的.c文件使用的全局变量...任何类型的帮助将不胜感激.谢谢.
tmp1.h文件
#ifndef TMP1_H_1
#define TMP1_H_1
double xxx[3] = {1.0,2.0,3.0};
#endif
Run Code Online (Sandbox Code Playgroud)
tmp1.c文件
#include "tmp1.h"
void testing()
{
int x = 0;
x++;
xxx[1] = 8.0;
}
Run Code Online (Sandbox Code Playgroud)
main1.c文件
#include <stdio.h>
#include "tmp1.h"
int main()
{
printf("hello world\n");
}
Run Code Online (Sandbox Code Playgroud) c ×1