# Specifying a .obj at LIB time.

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there anyway to specify which .obj file is used by the librarian to avoid the following error...
1>DEF.obj : warning LNK4006: "protected: __thiscall ####::CGraphics::CGraphics(struct HWND__ *)" (??0CGraphics@H####@@IAE@PAUHWND__@@@Z) already defined in ABC.obj; second definition ignored
and allow this:
#ifdef USE_ABC
#include "ABC.H"
#endif
#ifdef USE_DEF
#include "DEF.H"
#endif
I'm trying to avoid one of the obvious solutions:
#ifdef USE_ABC
#pragma comment(lib, "ABC.LIB")
#endif
#ifdef USE_DEF
#pragma comment(lib, "DEF.LIB")
#endif
due to the structure of the project (the desire for a single .lib) Any thoughts? I know there are probably a dozen ways to tackle this problem, I just have not found a simple elegant solution yet.

##### Share on other sites
Can you post some code, or try to explain better what you are trying to do.

##### Share on other sites
None of what you said makes any sense.

Anyways, you have a duplicate symbol somewhere in your project.

##### Share on other sites
I'm trying to create a graphics object based on a simple global define macro. Instead of chopping up the entire code base with a million ifdefs... I have one global file that defines what includes to use based on a single #define.

ABC.H would define how CGraphics functions X way. DEF.h would define how CGraphics functions Y way. And then App just calls the following based on what .h is included (based on what #define USE_ is set to).

	void CApp::InitGFX(void)	{		CGraphics::Create(Window()->GetHWND(), m_Width, m_Height);	}

App.h has the following define.

#include "Global.h"

Containing:

#ifdef USE_ABC#include "ABC.H"#endif#ifdef USE_DEF#include "DEF.H"#endif

##### Share on other sites
Quote:
 Original post by fpsgamerNone of what you said makes any sense.Anyways, you have a duplicate symbol somewhere in your project.

Obviously. =) By design. ABC and DEF both have class CGraphics implemented. See my last post. I need to choose either ABC's OR DEF's implementation, not both.

##### Share on other sites
Quote:
Original post by C0balt
Quote:
 Original post by fpsgamerNone of what you said makes any sense.Anyways, you have a duplicate symbol somewhere in your project.

Obviously. =) By design. ABC and DEF both have class CGraphics implemented. See my last post. I need to choose either ABC's OR DEF's implementation, not both.

Use a pragma as you mentioned before, or create a new build configuration. You can create a new build configuration by going into "Build > Configuration Manager". Once you've done that go into your project properties and specify the include directories and library dependencies for each of your build configurations.

##### Share on other sites
You can set up a new configuration in your project; ie "Release|Debug_foo" and "Release|Debug_bar".

Preferably, you would use logic directives to determine the contents of the file being linked, for instance:

// someobject1.hclass SomeObject {  ...};// someobject1.cppvoid SomeObject::SomeFunction() {  ...  // exhibits behavior A  ...}// someobject2.hclass SomeObject {  ...};// someobject2.cppvoid SomeObject::SomeFunction() {  ...  // exhibits behavior B  ...}// someobjectwrapper.h#ifdef USE_OBJECT_1#include "someobject1.h"#else#include "someobject2.h"#endif// someobjectwrapper.cpp#ifdef USE_OBJECT_1#include "someobject1.cpp"#else#include "someobject2.cpp"#endif

In this case, someobjectwrapper.obj gets built and linked, but not someobject1|2.obj.

It would, however, be more elegant to leave it all in one file and #ifdef the differences.

##### Share on other sites
Thanks for the ideas guys. I'll let you know what I end up with.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
632911
• Total Posts
3009183
• ### Who's Online (See full list)

There are no registered users currently online

×