链接错误2005或2001 [英] link error 2005 or 2001

查看:80
本文介绍了链接错误2005或2001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个非常好奇和独特的问题。

我正在使用bison和flex创建一个解析器。我在linux环境中完成了所有的开发工作。

项目包括flex和bison输出的源文件,然后

几个cpp从解析器创建数据结构的文件。

i使用gcc作为flex输出的编译器(因为它是ac文件)

和g ++作为剩余的编译器源文件。

链接所有目标文件以创建最终的可执行文件。


当我试图将相同的文件移植到Visual Studio时br $>
设置

i得到如下错误


CSymbolTable.obj:错误LNK2005:" struct symrec * __cdecl

returnSymbolTable(void)" (?returnSymbolTable @@ YAPAUsymrec @@ XZ)已经在CSymbolTable.obj中定义了


CSymbolTable.obj:错误LNK2005:" public:struct symrec * __thiscall

CSymbolTable :: returnSymbolTable(void)"

(?returnSymbolTable @ CSymbolTable @@ QAEPAUsymrec @@ XZ)已在

中定义CSymbolTable.obj

CSymbolTable.obj:错误LNK2005:" void __cdecl

enter_or_leave_the_struct(int)" (?enter_or_leave_the_struct @@ YAXH @ Z)

已在CSymbolTable.obj中定义

CSymbolTable.obj:错误LNK2005:" public:void __thiscall

CSymbolTable :: enter_or_leave_the_struct(int)"

(?enter_or_leave_the_struct @ CSymbolTable @@ QAEXH @ Z)已在

CSymbolTable.obj
$ b中定义$ b CSymbolTable.obj:错误LNK2005:" char * __cdecl

CreateAnUniqueName(char *)" (?CreateAnUniqueName @@ YAPADPAD @ Z)已经在CSymbolTable.obj中定义了


CSymbolTable.obj:错误LNK2005:" struct symrec * __cdecl putsym(char

*,int,char *,char *)" (?putsym @@ YAPAUsymrec @@ PADH00 @ Z)已经在CSymbolTable.obj中定义了



CSymbolTable.obj:错误LNK2005:" public:struct symrec * __thiscall

CSymbolTable :: putsym(char *,int,char *,char *)"

(?putsym @ CSymbolTable @@ QAEPAUsymrec @@ PADH00 @ Z)已定义于

CSymbolTable.obj

CSymbolTable.obj:错误LNK2005:" public:__ thishisall

CSymbolTable :: CSymbolTable(void)" (?? 0CSymbolTable @@ QAE @XZ)已经在CSymbolTable.obj中定义了



其中CSymbolTable.cpp是其中一个源文件。这种情况发生在

我使用的每个源文件。

i试图使用ifndef指令来避免多次包含,然后我得到

lnk2001错误为关于


parser.obj:错误LNK2001:未解析的外部符号" public:void

__thiscall CChannels :: AddGroupMeas(char *)"

(?AddGroupMeas @ CChannels @@ QAEXPAD @ Z)

parser.obj:错误LNK2001:未解析的外部符号" public:void

__thiscall CChannels: :AddASubGroup(char *)"

(?AddASubGroup @ CChannels @@ QAEXPAD @ Z)

parser.obj:错误LNK2001:未解析的外部符号" public:void

__thiscall CChannels :: AddASubGroup(char *)"

(?AddASubGroup @ CChannels @@ QAEXPAD @ Z)

parser.obj:错误LNK2001:未解析的外部符号" public:void

__thiscall CChannels :: AddGroupChannel(char *)"

(?AddGroupChannel @ CChannels @@ QAEXPAD @ Z)

parser.obj:错误LNK2001:未解决的外部符号public:void

__thiscall CChannels :: AddGroupChannel(char *)"

(?AddGroupChannel @ CChannels @@ QAEXPAD @ Z)

parser.obj:错误LNK2001:未解析的外部符号" public:void

__thiscall CChannels :: AddAChannel(char *)"

(?AddAChannel @ CChannels @@ QAEXPAD @ Z)


它非常令人沮丧,因为它与gcc和g ++的工作非常好


右边的任何指针方向对我很有帮助。


再次感谢


jc

I have a very curious and unique problem here.
I''m creating a parser using bison and flex. i did all the development
work in a linux environment.
the project includes the source files output from flex and bison, then
several cpp files to create a data structure from the parser.
i used gcc as the compiler for the flex output(as it is a c file)
and g++ as the compiler for the remaining source files.
linked all the object files to create the final executable file.

when i tried to port the same to the visual studio with the same
settings
i got error as follows

CSymbolTable.obj : error LNK2005: "struct symrec * __cdecl
returnSymbolTable(void)" (?returnSymbolTable@@YAPAUsymrec@@XZ) already
defined in CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "public: struct symrec * __thiscall
CSymbolTable::returnSymbolTable(void)"
(?returnSymbolTable@CSymbolTable@@QAEPAUsymrec@@XZ ) already defined in
CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "void __cdecl
enter_or_leave_the_struct(int)" (?enter_or_leave_the_struct@@YAXH@Z)
already defined in CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "public: void __thiscall
CSymbolTable::enter_or_leave_the_struct(int)"
(?enter_or_leave_the_struct@CSymbolTable@@QAEXH@Z) already defined in
CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "char * __cdecl
CreateAnUniqueName(char *)" (?CreateAnUniqueName@@YAPADPAD@Z) already
defined in CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "struct symrec * __cdecl putsym(char
*,int,char *,char *)" (?putsym@@YAPAUsymrec@@PADH00@Z) already defined
in CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "public: struct symrec * __thiscall
CSymbolTable::putsym(char *,int,char *,char *)"
(?putsym@CSymbolTable@@QAEPAUsymrec@@PADH00@Z) already defined in
CSymbolTable.obj
CSymbolTable.obj : error LNK2005: "public: __thiscall
CSymbolTable::CSymbolTable(void)" (??0CSymbolTable@@QAE@XZ) already
defined in CSymbolTable.obj

where CSymbolTable.cpp is one of the source files. this happens for
every source file that i use.
i tried to use ifndef directive to avoid multiple inclusion, then i get
lnk2001 error as follows

parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddGroupMeas(char *)"
(?AddGroupMeas@CChannels@@QAEXPAD@Z)
parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddASubGroup(char *)"
(?AddASubGroup@CChannels@@QAEXPAD@Z)
parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddASubGroup(char *)"
(?AddASubGroup@CChannels@@QAEXPAD@Z)
parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddGroupChannel(char *)"
(?AddGroupChannel@CChannels@@QAEXPAD@Z)
parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddGroupChannel(char *)"
(?AddGroupChannel@CChannels@@QAEXPAD@Z)
parser.obj : error LNK2001: unresolved external symbol "public: void
__thiscall CChannels::AddAChannel(char *)"
(?AddAChannel@CChannels@@QAEXPAD@Z)

it is very frustrating as it is working very well with gcc and g++

any pointers in the right direction will help me a lot.

thanks again

jc

推荐答案

k。************ @ gmail.com 写道:
k.************@gmail.com writes:

我这里有一个非常好奇和独特的问题。

我正在创建一个解析器使用野牛和flex。我在linux环境中完成了所有的开发工作。

项目包括flex和bison输出的源文件,然后

几个cpp
I have a very curious and unique problem here.
I''m creating a parser using bison and flex. i did all the development
work in a linux environment.
the project includes the source files output from flex and bison, then
several cpp



啊。这是comp.lang.c.你想要comp.lang.c ++。


-

Ben。

Ah. This is comp.lang.c. You want comp.lang.c++.

--
Ben.


k。************ @ gmail.com 写道:

i使用gcc作为flex输出的编译器(因为它是ac文件)

和g ++作为剩余源文件的编译器。 br />
链接所有目标文件以创建最终的可执行文件。


当我尝试将相同的文件移植到视觉工作室时

设置
i used gcc as the compiler for the flex output(as it is a c file)
and g++ as the compiler for the remaining source files.
linked all the object files to create the final executable file.

when i tried to port the same to the visual studio with the same
settings



我认为如果你愿意,你应该能够只使用C ++。但是,只有

一个关于VS的建议:它在源文件的扩展名

上区分C和C ++,你需要特殊的标志来强制它进入一个模式或<当扩展名不合适时,另外还有

I think you should be able to use just C++ if you want to. However, just
one advise about VS: it differentiates between C and C++ on the extension
of the sourcefile, you need special flags to force it into one mode or the
other when the extension doesn''t fit.


i得到如下错误


CSymbolTable .obj:错误LNK2005:" struct symrec * __cdecl

returnSymbolTable(void)" (?returnSymbolTable @@ YAPAUsymrec @@ XZ)已经

在CSymbolTable.obj中定义
i got error as follows

CSymbolTable.obj : error LNK2005: "struct symrec * __cdecl
returnSymbolTable(void)" (?returnSymbolTable@@YAPAUsymrec@@XZ) already
defined in CSymbolTable.obj



好​​的,?returnSymbolTable @@ YAPAUsymrec @@ XZ"是两次出现的符号
,之前的部分是解码符号 - 这是C ++的效果
名称修改,所以至少使用C ++编译器编译该文件。

无论如何,这个特定的函数定义了两次,一次在

CSymbolTable.obj中,另一个定义在,hehe,CSymbolTable.obj。 IOW,

你以某种方式设法包含该对象文件两次。我想这是你的IDE处理错误的

,所以请把它带到一个与之相关的论坛,而不是clc。

Okay, the "?returnSymbolTable@@YAPAUsymrec@@XZ" is the symbol occuring
twice, the part before is the decoded symbol - this is an effect of C++
name mangling, so that file at least was compiled using a C++ compiler.
Anyhow, this particular function is defined twice, once in
CSymbolTable.obj and the other definition in, hehe, CSymbolTable.obj. IOW,
you somehow managed to include that objectfile twice. I guess this is a
handling error of your IDE, so please take this to a forum related to that
rather than clc.


其中CSymbolTable.cpp是源文件之一。我使用的每个源文件都会发生这种情况。

i试图使用ifndef指令来避免多次包含
where CSymbolTable.cpp is one of the source files. this happens for
every source file that i use.
i tried to use ifndef directive to avoid multiple inclusion



等等:请构建你的标题,以便它们可以在单个翻译单元(即使用包含警卫)中包含超过

,并且还包括

他们不会定义(!!!)任何强符号(即没有变量

定义,除了静态常量和没有函数定义

除了内联函数)。这应该是非常基本的C而且没有什么可以尝试使用。为了解决问题。


关于将C代码与C ++代码集成的最后一件事:C ++

需要''extern'C"''on a函数声明,以便它导致

与C编译器生成的符号相同。进一步的问题应该是一个C ++小组,因为这是这个小组的主题漂移。


最后,为了解决这些问题,你将不得不a)创建一个

最小的例子和b)提供一些真实的代码和一些关于你用什么文件做什么的实际信息。根据你的描述,我只能猜到你b $ b做了什么。


Uli

Wait: please structure your headers so that they can be included more than
once in a single translation unit (i.e. using include guards) and also
that they don''t define(!!!) any strong symbols (i.e. no variable
definitions apart from static constant ones and no function definitions
apart from inline functions). This should be very basic C and nothing that
you "try to use" in order to fix problems.

One last thing about integrating C code with C++ code: C++
needs ''extern "C"'' on a function declaration in order for it to result in
the same symbol as a C compiler would generate. Further questions should
be in a C++ group though, as this is drifting of the topic of this group.

Lastly, in order to solve such problems, you will have to a) create a
minimal example and b) provide some real code and some real info on what
you did with what file. From your description I can only guess what you
did.

Uli




< k。************ @ gmail.com写信息

新闻:11 ******** **************@e3g2000cwe.googlegro ups.com ...

<k.************@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...

>我有一个非常好奇和独特的问题这里。

我正在使用bison和flex创建一个解析器。我在linux环境中完成了所有的开发工作。

项目包括flex和bison输出的源文件,然后

几个cpp从解析器创建数据结构的文件。

i使用gcc作为flex输出的编译器(因为它是ac文件)

和g ++作为剩余的编译器源文件。

链接所有目标文件以创建最终的可执行文件。


当我试图将相同的文件移植到Visual Studio时br $>
设置

i得到如下错误


CSymbolTable.obj:错误LNK2005:" struct symrec * __cdecl

returnSymbolTable(void)" (?returnSymbolTable @@ YAPAUsymrec @@ XZ)已经

在CSymbolTable.obj中定义
>I have a very curious and unique problem here.
I''m creating a parser using bison and flex. i did all the development
work in a linux environment.
the project includes the source files output from flex and bison, then
several cpp files to create a data structure from the parser.
i used gcc as the compiler for the flex output(as it is a c file)
and g++ as the compiler for the remaining source files.
linked all the object files to create the final executable file.

when i tried to port the same to the visual studio with the same
settings
i got error as follows

CSymbolTable.obj : error LNK2005: "struct symrec * __cdecl
returnSymbolTable(void)" (?returnSymbolTable@@YAPAUsymrec@@XZ) already
defined in CSymbolTable.obj



不知何故,你连接相同的.obj文件两次,也许你正在创建一个

静态库,然后主可执行文件使用.cpp文件和

静态库?


因为它是链接器而不是编译器错误,所以#ifndef不太可能

帮助你。其他一些事情可能导致这种情况,但如果代码在

gcc下运行,那么它看起来就像是一个纯粹的windows makefile(项目文件)问题。

Somehow you are linking the same .obj file twice, perhaps you are creating a
static library, then the main executable uses both the .cpp file and the
static library?

Since it''s a linker and not compiler error, it''s unlikely that #ifndef can
help you. Some other things could cause this, but if the code works under
gcc, then it looks like purely a windows makefile (project file) issue.


这篇关于链接错误2005或2001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆