另一个C源文件set.c里面进行外部申明:extern int ShenNum, YunNum;
可是编译出错,出错信息为:
set.obj : error LNK2005: _Yun already defined in bingji.obj
看出错信息,似乎这个叫_Yun的变量已经在bingji里定义了,这里重复定义了。
可是我的bingji.c里面并没有定义这个变量,也没有定义“Yun”这个变量。倒是有个叫YunNum的变量。
这是为什么?怎么排错?
14 个解决方案
#1
对了,以上两个文件里的YunNum变量均在函数外部定义。一个直接定义,一个用extern申明,应该没有错吧?
怎么会提示 “_Yun已被定义”?,就算短横线是编译系统加上去的,可是我Yun这个变量从来没有定义啊!
怎么会提示 “_Yun已被定义”?,就算短横线是编译系统加上去的,可是我Yun这个变量从来没有定义啊!
#2
extern int ShenNum;
extern int YunNum;
#3
Sorry,看错了。有可能是函数重复定义。
#4
你把这两行分成4行写写试试呢?
#5
是不是跟这个有关?
有在bingji.c中定义了:
unsigned char shen_table[256][16];
unsigned char yun_table[256][16];
然后在set.c中申明了:
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
跟这个有关吗?这种定义和申明方法对不对?
有在bingji.c中定义了:
unsigned char shen_table[256][16];
unsigned char yun_table[256][16];
然后在set.c中申明了:
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
跟这个有关吗?这种定义和申明方法对不对?
#6
oops……类型最好一致。
#7
LZ可以尝试注释掉一半代码,看看是否有错误发生,然后再注释掉一半。
#8
编译输入信息是这样的(前面编译没有错误,然后下面链接的时候是这样的):
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
Debug/bingji.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
bingji.dll - 3 error(s), 44 warning(s)
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
Debug/bingji.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
bingji.dll - 3 error(s), 44 warning(s)
#9
Yun会不会是宏替换后产生的名字?
#10
我注释掉了set.c中所有的函数,只留前面变量定义的申明部分,结果还是有错误:
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
bingji.obj : error LNK2001: unresolved external symbol _SetDlgProc@16
Debug/bingji.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
bingji.dll - 4 error(s), 5 warning(s)
此时,set.c中的内容仅仅是下面的内容:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <CommCtrl.h>
#include "Imm.h"
#include "bingji.h"
#include "resource.h"
extern LRESULT CALLBACK SetDlgProc(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam);
extern LRESULT CALLBACK SetDlgProc4(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam);
extern HINSTANCE hInstance;
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
extern int ShenNum;
extern int YunNum;
extern int i;
各位帮忙看看,到底错在哪里?
#11
把extern unsigned char shen_table[256][16];
里面的unsigned 也干掉试试么...
里面的unsigned 也干掉试试么...
#12
找到原因了,原来是头文件bingji.h中有这样的内容:
struct PINGYI
{
unsigned char SuoXie;
unsigned char Mu[5];
};
struct PINGYI Shen[24]={{'b',"b"},{'p',"p"},{'m',"m"},{'f',"f"},{'d',"d"},{'t',"t"},{'n',"n"},{'l',"l"},
{'g',"g"},{'k',"k"},{'h',"h"},{'j',"j"},{'q',"q"},{'x',"x"},{'v',"zh"},{'i',"ch"},{'u',"sh"},
{'r',"r"},{'z',"z"},{'c',"c"},{'s',"s"},{'y',"y"},{'w',"w"},{'0',"0"}};
struct PINGYI Yun[25]={{'a',"a"},{'o',"o"},{'e',"e"},{'i',"i"},{'u',"u"},{'l',"ai"},{'z',"ei"},{'v',"ui"},
{'k',"ao"},{'b',"ou"},{'q',"iu"},{'x',"ie"},{'j',"an"},{'f',"en"},{'n',"in"},{'p',"un"},{'h',"ang"},
{'g',"eng"},{'y',"ing"},{'s',"ong"},{'w',"ia"},{'c',"iao"},{'m',"ian"},{'r',"uan"},{'d',"iang"}};
这里面含有变量的定义,而这个头文件被两个C源文件包含,所以变量被定义了两次。
struct PINGYI
{
unsigned char SuoXie;
unsigned char Mu[5];
};
struct PINGYI Shen[24]={{'b',"b"},{'p',"p"},{'m',"m"},{'f',"f"},{'d',"d"},{'t',"t"},{'n',"n"},{'l',"l"},
{'g',"g"},{'k',"k"},{'h',"h"},{'j',"j"},{'q',"q"},{'x',"x"},{'v',"zh"},{'i',"ch"},{'u',"sh"},
{'r',"r"},{'z',"z"},{'c',"c"},{'s',"s"},{'y',"y"},{'w',"w"},{'0',"0"}};
struct PINGYI Yun[25]={{'a',"a"},{'o',"o"},{'e',"e"},{'i',"i"},{'u',"u"},{'l',"ai"},{'z',"ei"},{'v',"ui"},
{'k',"ao"},{'b',"ou"},{'q',"iu"},{'x',"ie"},{'j',"an"},{'f',"en"},{'n',"in"},{'p',"un"},{'h',"ang"},
{'g',"eng"},{'y',"ing"},{'s',"ong"},{'w',"ia"},{'c',"iao"},{'m',"ian"},{'r',"uan"},{'d',"iang"}};
这里面含有变量的定义,而这个头文件被两个C源文件包含,所以变量被定义了两次。
#13
#14
感谢!用的还是你的干掉一部分的方法试出来的,最后发现,注释掉bingji.h前后发生的变化。终于发现了这个错误。
#1
对了,以上两个文件里的YunNum变量均在函数外部定义。一个直接定义,一个用extern申明,应该没有错吧?
怎么会提示 “_Yun已被定义”?,就算短横线是编译系统加上去的,可是我Yun这个变量从来没有定义啊!
怎么会提示 “_Yun已被定义”?,就算短横线是编译系统加上去的,可是我Yun这个变量从来没有定义啊!
#2
extern int ShenNum;
extern int YunNum;
#3
Sorry,看错了。有可能是函数重复定义。
#4
你把这两行分成4行写写试试呢?
#5
是不是跟这个有关?
有在bingji.c中定义了:
unsigned char shen_table[256][16];
unsigned char yun_table[256][16];
然后在set.c中申明了:
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
跟这个有关吗?这种定义和申明方法对不对?
有在bingji.c中定义了:
unsigned char shen_table[256][16];
unsigned char yun_table[256][16];
然后在set.c中申明了:
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
跟这个有关吗?这种定义和申明方法对不对?
#6
oops……类型最好一致。
#7
LZ可以尝试注释掉一半代码,看看是否有错误发生,然后再注释掉一半。
#8
编译输入信息是这样的(前面编译没有错误,然后下面链接的时候是这样的):
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
Debug/bingji.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
bingji.dll - 3 error(s), 44 warning(s)
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
Debug/bingji.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
bingji.dll - 3 error(s), 44 warning(s)
#9
Yun会不会是宏替换后产生的名字?
#10
我注释掉了set.c中所有的函数,只留前面变量定义的申明部分,结果还是有错误:
Linking...
set.obj : error LNK2005: _Yun already defined in bingji.obj
set.obj : error LNK2005: _Shen already defined in bingji.obj
set.obj : warning LNK4006: _Yun already defined in bingji.obj; second definition ignored
set.obj : warning LNK4006: _Shen already defined in bingji.obj; second definition ignored
Creating library Debug/bingji.lib and object Debug/bingji.exp
bingji.obj : error LNK2001: unresolved external symbol _SetDlgProc@16
Debug/bingji.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
bingji.dll - 4 error(s), 5 warning(s)
此时,set.c中的内容仅仅是下面的内容:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <CommCtrl.h>
#include "Imm.h"
#include "bingji.h"
#include "resource.h"
extern LRESULT CALLBACK SetDlgProc(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam);
extern LRESULT CALLBACK SetDlgProc4(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam);
extern HINSTANCE hInstance;
extern unsigned char shen_table[256][16];
extern unsigned char yun_table[256][16];
extern int ShenNum;
extern int YunNum;
extern int i;
各位帮忙看看,到底错在哪里?
#11
把extern unsigned char shen_table[256][16];
里面的unsigned 也干掉试试么...
里面的unsigned 也干掉试试么...
#12
找到原因了,原来是头文件bingji.h中有这样的内容:
struct PINGYI
{
unsigned char SuoXie;
unsigned char Mu[5];
};
struct PINGYI Shen[24]={{'b',"b"},{'p',"p"},{'m',"m"},{'f',"f"},{'d',"d"},{'t',"t"},{'n',"n"},{'l',"l"},
{'g',"g"},{'k',"k"},{'h',"h"},{'j',"j"},{'q',"q"},{'x',"x"},{'v',"zh"},{'i',"ch"},{'u',"sh"},
{'r',"r"},{'z',"z"},{'c',"c"},{'s',"s"},{'y',"y"},{'w',"w"},{'0',"0"}};
struct PINGYI Yun[25]={{'a',"a"},{'o',"o"},{'e',"e"},{'i',"i"},{'u',"u"},{'l',"ai"},{'z',"ei"},{'v',"ui"},
{'k',"ao"},{'b',"ou"},{'q',"iu"},{'x',"ie"},{'j',"an"},{'f',"en"},{'n',"in"},{'p',"un"},{'h',"ang"},
{'g',"eng"},{'y',"ing"},{'s',"ong"},{'w',"ia"},{'c',"iao"},{'m',"ian"},{'r',"uan"},{'d',"iang"}};
这里面含有变量的定义,而这个头文件被两个C源文件包含,所以变量被定义了两次。
struct PINGYI
{
unsigned char SuoXie;
unsigned char Mu[5];
};
struct PINGYI Shen[24]={{'b',"b"},{'p',"p"},{'m',"m"},{'f',"f"},{'d',"d"},{'t',"t"},{'n',"n"},{'l',"l"},
{'g',"g"},{'k',"k"},{'h',"h"},{'j',"j"},{'q',"q"},{'x',"x"},{'v',"zh"},{'i',"ch"},{'u',"sh"},
{'r',"r"},{'z',"z"},{'c',"c"},{'s',"s"},{'y',"y"},{'w',"w"},{'0',"0"}};
struct PINGYI Yun[25]={{'a',"a"},{'o',"o"},{'e',"e"},{'i',"i"},{'u',"u"},{'l',"ai"},{'z',"ei"},{'v',"ui"},
{'k',"ao"},{'b',"ou"},{'q',"iu"},{'x',"ie"},{'j',"an"},{'f',"en"},{'n',"in"},{'p',"un"},{'h',"ang"},
{'g',"eng"},{'y',"ing"},{'s',"ong"},{'w',"ia"},{'c',"iao"},{'m',"ian"},{'r',"uan"},{'d',"iang"}};
这里面含有变量的定义,而这个头文件被两个C源文件包含,所以变量被定义了两次。
#13
#14
感谢!用的还是你的干掉一部分的方法试出来的,最后发现,注释掉bingji.h前后发生的变化。终于发现了这个错误。