Link to home
Start Free TrialLog in
Avatar of PeterTokeHedenAhlgren
PeterTokeHedenAhlgren

asked on

How to get around error LNK2005

As I have found out, there ar e several reasons one might experience error LNK2005.

In my case I have an MFC project, and a "standard" C++ project, the latter being a library of many different functions. Since I'm working a lot with templates, almost all my code in this library is in header files.

Now I'd like to use one of my classes from the library in the MFC project. Including that file in CMyDoc.h results in several error LNK2005 messages such as.

"1>SeriesView.obj : error LNK2005: "void __cdecl ASU::start_timer(class boost::timer &)" (?start_timer@ASU@@YAXAAVtimer@boost@@@Z) already defined in ASU Studio.obj"

The function start_timer looks like this

void __declspec(dllexport) start_timer(boost::timer &aT) { aT.restart(); }

How do I get around having this header included by all .cpp files that by some "cross-reference" include CMyDoc.h?

I hope you guys can help me out on this. Thanks in advance!!!
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterTokeHedenAhlgren
PeterTokeHedenAhlgren

ASKER

Inlining indeed solved my problem, though I'm sure the solution with putting code in a .cpp would as well. Thanks a lot!!!