我编程中的问题 希望高手快帮帮忙

wwankof 2008-11-18 01:58:27
//Global.h
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
#include <iomanip.h>
#include <time.h>
#include <malloc.h>
#include <string.h>
#include <fstream.h>


#include "defines.h"



struct NODE{
double x;
double y;
double z;
double rho;
double P;
double u;
double v;
double w;
double f[Q];
double F[Q];

};

int NBLOCK;
int **BLOCK;
NODE ****node;


void Grid_Read();
void Grid_DataDeal();


//Grid Read.cpp
#include "Global.h"

void Grid_read()
{
int i=0,j=0,k=0,l=0;

FILE *fp;
if ( (fp = fopen( "Grid/airfoil.grd", "r" )) == NULL )
printf("ERROR on open Grid!\n");

fscanf( fp, "%d",&NBLOCK);

BLOCK = new int*[NBLOCK];
for(i = 0; i < NBLOCK; i++)
{
BLOCK[i] = new int[3];
}
for(i=0;i<NBLOCK;i++)
for(j=0;j<3;j++)
{
fscanf( fp, "%d",&BLOCK[i][j]);
}

node = new NODE ***[NBLOCK];
for( i=0;i<NBLOCK;i++)
{
node[i]= new NODE**[BLOCK[i][0]];
for(j=0;j<BLOCK[i][0];j++)
{
node[i][j]=new NODE*[BLOCK[i][1]];
for(k=0;k<BLOCK[i][j];k++)
{
node[i][j][k]=new NODE[BLOCK[i][2]];
}
}
}


for(i=0;i<NBLOCK;i++)
{
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fscanf( fp, "%lf",&node[i][j][k][l].x);
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fscanf( fp, "%lf",&node[i][j][k][l].y);
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fscanf( fp, "%lf",&node[i][j][k][l].z);
}
fclose(fp);

cout<<"Read Grid successfully!!!"<<endl;
}


//Grid deal.cpp
#include "Global.h"

void Grid_DataDeal()
{
extern NODE ****node;
extern int NBLOCK;
extern int **BLOCK;

int i,j,k,l;
FILE *outfp;
char temp[500];
sprintf(temp,"Grid.dat");
outfp=fopen("output/temp","w");
fprintf(outfp,"%d\n",NBLOCK);
for(i=0;i<NBLOCK;i++)
fprintf(outfp,"%d\t%d\t%d\n",BLOCK[i][0],BLOCK[i][1],BLOCK[i][2]);
for(i=0;i<NBLOCK;i++)
{
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fprintf( outfp, "%lf",&node[i][j][k][l].x);
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fprintf( outfp, "%lf",&node[i][j][k][l].y);
for(l=0;l<BLOCK[i][2];l++)
for(k=0;k<BLOCK[i][1];k++)
for(j=0;j<BLOCK[i][0];j++)
fprintf( outfp, "%lf",&node[i][j][k][l].z);
}
fclose(outfp);
cout<<"Datadeal Grid successfully!"<<endl;
}


//main.cpp
#include "Global.h"

void main()
{

Grid_Read();
Grid_DataDeal();
}

编译的时候出现
Linking...
Grid Read.obj : error LNK2005: "struct NODE * * * * node" (?node@@3PAPAPAPAUNODE@@A) already defined in Grid DataDeal.obj
Grid Read.obj : error LNK2005: "int NBLOCK" (?NBLOCK@@3HA) already defined in Grid DataDeal.obj
Grid Read.obj : error LNK2005: "int * * BLOCK" (?BLOCK@@3PAPAHA) already defined in Grid DataDeal.obj
main.obj : error LNK2005: "struct NODE * * * * node" (?node@@3PAPAPAPAUNODE@@A) already defined in Grid DataDeal.obj
main.obj : error LNK2005: "int NBLOCK" (?NBLOCK@@3HA) already defined in Grid DataDeal.obj
main.obj : error LNK2005: "int * * BLOCK" (?BLOCK@@3PAPAHA) already defined in Grid DataDeal.obj
main.obj : error LNK2001: unresolved external symbol "void __cdecl Grid_Read(void)" (?Grid_Read@@YAXXZ)
Debug/ISLBM.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.


请高手指点 应该如何修改
...全文
153 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwankof 2008-11-18
  • 打赏
  • 举报
回复
楼上的 高手 我qq77270265 请加我一下 这样方便些 谢谢
wwankof 2008-11-18
  • 打赏
  • 举报
回复
我进行修改后 出现了上面的错误


我是不是应该在另外一个CPP中还要加入什么语句呢
wwankof 2008-11-18
  • 打赏
  • 举报
回复
但是我改了之后 又出现了以下错误
Compiling...
Grid DataDeal.cpp
Linking...
Grid DataDeal.obj : error LNK2001: unresolved external symbol "struct NODE * * * * node" (?node@@3PAPAPAPAUNODE@@A)
Grid DataDeal.obj : error LNK2001: unresolved external symbol "int * * BLOCK" (?BLOCK@@3PAPAHA)
Grid DataDeal.obj : error LNK2001: unresolved external symbol "int NBLOCK" (?NBLOCK@@3HA)
main.obj : error LNK2001: unresolved external symbol "void __cdecl Grid_Read(void)" (?Grid_Read@@YAXXZ)
Debug/ISLBM.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错.
liumingrong 2008-11-18
  • 打赏
  • 举报
回复
支持,在头文件中用extern 声明,在你认为合适的一个cpp文件中定义它即可
[Quote=引用 7 楼 hai040 的回复:]
//Global.h
extern int NBLOCK;
extern int **BLOCK;
extern NODE ****node;

//任一个cpp
int NBLOCK;
int **BLOCK;
NODE ****node;
[/Quote]
hai040 2008-11-18
  • 打赏
  • 举报
回复
//Global.h
extern int NBLOCK;
extern int **BLOCK;
extern NODE ****node;

//任一个cpp
int NBLOCK;
int **BLOCK;
NODE ****node;
wwankof 2008-11-18
  • 打赏
  • 举报
回复
另外 用什么语句可以定义全局变量呢
wwankof 2008-11-18
  • 打赏
  • 举报
回复
我应该把全局变量 定义在哪个cpp中呢
Repeaterbin 2008-11-18
  • 打赏
  • 举报
回复
好像因为你的全局变量 定义在 .h中的原因
放在.cpp中应该就好了
wwankof 2008-11-18
  • 打赏
  • 举报
回复
那我读出来的数据 怎么在另外一个文件中调用呢
liumingrong 2008-11-18
  • 打赏
  • 举报
回复
不要在头文件中定义变量
wwankof 2008-11-18
  • 打赏
  • 举报
回复
自己顶一下 高手 在线等呢 快来帮帮忙啊 解决直接给分

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧