Skip to main content
GameDev.net gamedev.net
🔒 Locked

Specifying a .obj at LIB time.

Started by C0balt May 24, 2008 at 10:05 PM 6 replies 1k views
Original Post
C0balt
C0balt
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.
Cobalt
force_of_will
force_of_will
Can you post some code, or try to explain better what you are trying to do.
fpsgamer
fpsgamer
None of what you said makes any sense.

Anyways, you have a duplicate symbol somewhere in your project.
C0balt
C0balt
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
Cobalt
C0balt
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.
Cobalt
fpsgamer
fpsgamer
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.
erissian
erissian
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.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
C0balt
C0balt
Thanks for the ideas guys. I'll let you know what I end up with.
Cobalt

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.