c++ error lnk2005 when a global function is included

576 views Asked by At

I am working on a dll project, and it had been working well until I added a new .h, which includes a global function and a struct. Then the compiling (or link) failed.

Here is the error message:

1>RobotReality.obj : error LNK2005: "double __cdecl GetNumber(void)" (?GetNumber@@YANXZ) [[已经在 dllmain.obj 中定义  translate: this has been defined in dllmain.obj]]

1>stdafx.obj : error LNK2005: "double __cdecl GetNumber(void)" (?GetNumber@@YANXZ) [[已经在 dllmain.obj 中定义  translate: this has been defined in dllmain.obj]]

I have added "#pragma once" but the problem still exits.

How to solve this problem?

Thanks!

1

There are 1 answers

0
il Giovine On

Declare them 'static' and let the compiler do the work.