473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

link error 2005 or 2001

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

Nov 17 '06 #1
10 2815
k.************@gmail.com writes:
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
Ah. This is comp.lang.c. You want comp.lang.c++.

--
Ben.
Nov 17 '06 #2
k.************@gmail.com wrote:
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 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 got error as follows

CSymbolTable.obj : error LNK2005: "struct symrec * __cdecl
returnSymbolTable(void)" (?returnSymbolTable@@YAPAUsymrec@@XZ) already
defined in CSymbolTable.obj
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.
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
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

Nov 17 '06 #3

<k.************@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>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
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.
Nov 20 '06 #4
Hey
thanks for the reply. i got the problem sorted. you guys are right. it
was my bad. the problem being i included all the cpp files in the
source files list and also in the linker setting, i added the object
files.
once i removed the object file names from the link options the lnk2005
error disappeared. now i got the unresolved external variable error.

for example
in cgrammar.tab.cpp
i defined three variables
int start_of_enum_list;
int block_struct_flag;
int bEndOfA2ML;

in lex.yy.c
i defined these three variable as extern

extern int start_of_enum_list;
extern int block_struct_flag;
extern int bEndOfA2ML;

now after compiling i get
lnk2001 error
lex.yy.obj : error lnk2001 : unresolved external symbol _bEndOfA2ML
and for all the three variables

hope i can resolve this

thanks again
jc
Ben Voigt wrote:
<k.************@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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

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.
Nov 21 '06 #5
k.************@gmail.com wrote:
>
thanks for the reply. i got the problem sorted. you guys are right.
it was my bad. the problem being i included all the cpp files in the
source files list and also in the linker setting, i added the object
files.
once i removed the object file names from the link options the lnk2005
error disappeared. now i got the unresolved external variable error.
Please don't top-post. Your answer belongs after the quoted (and
snipped) material to which you reply. It may also be intermixed.
The snipping removes material not germane to your reply.

The presence of 'cpp' above indicates that you are confusing C++
with C. Your source files should end in .c, or you are on the
wrong newsgroup.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 21 '06 #6
k.************@gmail.com wrote:
Hey
Take note that it's important not to top-post. Refer to the links
below.
(Taken from one of CBFalconer's sigs)
Some informative links:
<news:news.announce.newusers>
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>

Now coming to your problem:
... now i got the unresolved external variable error.

for example
in cgrammar.tab.cpp
i defined three variables
int start_of_enum_list;
int block_struct_flag;
int bEndOfA2ML;
Check if these are external variables. Also don't qualify them with the
static keyword.
in lex.yy.c
i defined these three variable as extern

extern int start_of_enum_list;
extern int block_struct_flag;
extern int bEndOfA2ML;
Check if you've placed the above declarations outside any functions.

Now try to compile again.
Be warned that linking in C++ is significantly different to C. If your
code is C++, then post future follow-ups to comp.lang.c++.

Nov 21 '06 #7

CBFalconer wrote:
k.************@gmail.com wrote:

thanks for the reply. i got the problem sorted. you guys are right.
it was my bad. the problem being i included all the cpp files in the
source files list and also in the linker setting, i added the object
files.
once i removed the object file names from the link options the lnk2005
error disappeared. now i got the unresolved external variable error.

Please don't top-post. Your answer belongs after the quoted (and
snipped) material to which you reply. It may also be intermixed.
The snipping removes material not germane to your reply.

The presence of 'cpp' above indicates that you are confusing C++
with C. Your source files should end in .c, or you are on the
wrong newsgroup.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
i'm sorry. i always forget which is the right way top post or bottom
post

Nov 21 '06 #8

santosh wrote:
k.************@gmail.com wrote:
Hey

Take note that it's important not to top-post. Refer to the links
below.
(Taken from one of CBFalconer's sigs)
Some informative links:
<news:news.announce.newusers>
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>

Now coming to your problem:
... now i got the unresolved external variable error.

for example
in cgrammar.tab.cpp
i defined three variables
int start_of_enum_list;
int block_struct_flag;
int bEndOfA2ML;

Check if these are external variables. Also don't qualify them with the
static keyword.
in lex.yy.c
i defined these three variable as extern

extern int start_of_enum_list;
extern int block_struct_flag;
extern int bEndOfA2ML;

Check if you've placed the above declarations outside any functions.

Now try to compile again.
Be warned that linking in C++ is significantly different to C. If your
code is C++, then post future follow-ups to comp.lang.c++.
lex.yy.c is the output of the flex.
cgrammar.tab.cpp is the output of bison.
lex.yy.c is a C code
cgrammar.tab.cpp is a cpp code

so actually i'm trying to link C and C++ code to get the final output.

in linux i compile lex.yy.c using gcc and the remaining c++ code using
g++ and finally link it with no trouble at all. now when i port the
same to the visual studio i got stuck

i posted in this forum as one part of the problem is a C code

thanks

Nov 21 '06 #9
k.************@gmail.com wrote:
>
CBFalconer wrote:
[...]
Please don't top-post. Your answer belongs after the quoted (and
snipped) material to which you reply. It may also be intermixed.
The snipping removes material not germane to your reply.
[...]
i'm sorry. i always forget which is the right way top post or bottom
post
Neither. Inline posting is correct. (On short responses such as
this one, inline and bottom posting appear the same.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 21 '06 #10
k.************@gmail.com wrote:
CBFalconer wrote:
.... snip ...
>>
Please don't top-post. Your answer belongs after the quoted (and
snipped) material to which you reply. It may also be intermixed.
The snipping removes material not germane to your reply.

The presence of 'cpp' above indicates that you are confusing C++
with C. Your source files should end in .c, or you are on the
wrong newsgroup.

i'm sorry. i always forget which is the right way top post or bottom
post
All you have to think about is an order that makes readable sense.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 21 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: frr | last post by:
Hi, After upgrading to 2.4 (from 2.3), I'm getting a weird syntax error: >>> import themes Traceback (most recent call last): File "<interactive input>", line 1, in ? File "themes.py", line...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
5
by: Edward Mitchell | last post by:
I am trying to include two class files into a web service project. The structure I have is a top level solution and project in a folder and below that, the web service project in it's own folder. ...
7
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything...
13
by: mjf | last post by:
I'm consuming a web service produced by a Java, non-Microsoft system. The response will have two complex elements. One of those has an array of items. Before I get back to my code, the system...
1
by: manfred | last post by:
Hi Together, I tried to build a webservice proxy using a wsdl, generated in the sun/java world. I used the .Net 2003 Version, choosing there VC++. The steps I did: 1. Visual C++ Projekte /...
1
by: Moon Chung | last post by:
Hello, Has anyone used Testing Tools from WS-I (www.ws-i.org)? I am building a Web Service and hopefully it would be interoperable. When I ran Testing Tool, I am getting BP1212 error. I...
2
by: ahogan | last post by:
Previously posted on comp.databases.oracle.misc. Apologies to those who read both groups. I have created a link using generic connectivity from an Oracle 10.2.0.1 instance running on windows...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.