Sign in to follow this  

Specifying a .obj at LIB time.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
None 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 this post


Link to post
Share on other sites
Quote:
Original post by C0balt
Quote:
Original post by fpsgamer
None 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 this post


Link to post
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.h

class SomeObject {
...
};

// someobject1.cpp

void SomeObject::SomeFunction() {
...
// exhibits behavior A
...
}

// someobject2.h

class SomeObject {
...
};

// someobject2.cpp

void 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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this