473,399 Members | 4,192 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,399 software developers and data experts.

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 24191
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
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
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
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
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
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
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
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
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
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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,...
0
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...

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.