473,499 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resolve error LNK2005 - function already defined

Hello

I have a function which I have defined in a .h file called LogError. I use
a sort of global .h file which is included in all cpp files - StdAfx.h -
this file #include's my .h file with this function LogError.

In my program I have several .c/.h files. If I use LogError in just one of
these .c files all is well. However, if I use LogError in two or more .c
files, then I get this sort of link error:

error LNK2005: "int __cdecl LogError(char * const)" (?LogError@@YAHQAD@Z)
already defined in Page3.obj

I had a go at putting - extern int LogError(TCHAR szErrorMsg[]) in stdafx.h
and even some other files - but that did not seem to help.

How can I resolve this?

Angus Comber
an***@NOSPAMiteloffice.com
Nov 14 '05 #1
1 24209
Angus Comber wrote:
Hello

I have a function which I have defined in a .h file called LogError. I use
a sort of global .h file which is included in all cpp files - StdAfx.h -
this file #include's my .h file with this function LogError.

In my program I have several .c/.h files. If I use LogError in just one of
these .c files all is well. However, if I use LogError in two or more .c
files, then I get this sort of link error:

error LNK2005: "int __cdecl LogError(char * const)" (?LogError@@YAHQAD@Z)
already defined in Page3.obj

I had a go at putting - extern int LogError(TCHAR szErrorMsg[]) in stdafx.h
and even some other files - but that did not seem to help.

How can I resolve this?


By not defining functions in headers. The definition of the function
should go into a translation unit (what you call ".c files"). The
header should have its prototype.

An unrelated problem: Since you refer to "cpp files" above, there it is
possible that you are invoking your compiler as a C++ compiler. If you
are writing C, then make sure that you are invoking your compiler as a C
compiler. If you are writing C++, your questions belong in
news:comp.lang.c++, where they deal with that heretical language, not here.
Nov 14 '05 #2

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

Similar topics

1
9462
by: Kay | last post by:
I already specified to ignore specific library: MSVCPRT.lib MSVCRT.lib LIBC.lib MSVCRTD.lib LIBCD.lib command line is like: /INCREMENTAL /NOLOGO /DLL /NODEFAULTLIB:"MSVCPRT.lib MSVCRT.lib LIBC.lib...
0
507
by: Taran | last post by:
Hi all, I have this config.h file which has all the declarations for the vars being used in the application. There are no compilation errors but link errors for all the vars declared in this...
1
7867
by: sethuganesh | last post by:
HI, i have ported vc++ 6.0 code to visual studio 2005. During batch build in debug mode i din't get any error.But if i build the same in release mode i am getting the following error. ...
10
2822
by: k.jayachandran | last post by:
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...
1
11940
nabh4u
by: nabh4u | last post by:
hi, i am getting a link error in my program which states that some variable which i declared in my header file is already defined in the object file. The error is like this: error LNK2005:...
6
9813
by: fcvcnet | last post by:
Hi all, I defined a class, as fellows: // Segment.h #pragma once #include "MyPoint.h" enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE} twolinesolutioncases;
1
5299
by: sahilrekhi | last post by:
Hi i am working on a graphical user interface deisgn programme. when i compile the file i i get the following output with the mentioned errors: 1>------ Rebuild All started: Project: guiq,...
1
5704
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include...
9
3200
by: dewi | last post by:
Dear All, I have several problem about VC++. I succeed to convert Simulink MATLAB to C code using Real-Time Workshop. I am trying to compile a C code using Visual C++ and found the error. Can...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.