View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# How to verify that library and app were compiled with same switches?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Zbychs  Members

Posted 16 January 2011 - 01:23 AM

Hi,

I have a library that can be compiled (C++) with a certain define (either -DBRAND=1 or -DBRAND=2), and I have an application that uses this library.
Both library and application have to be compiled with the same value of BRAND.

Is there a way to verify at compile/link time that libary was compiled with the same BRAND value as application?

Zbyl

Posted 16 January 2011 - 07:54 AM

You could use the ## token pasting operator to rename some or more of your functions so that the linker won't find them when the define is set incorrectly. Or just use a standard #ifdef to rename one or two of them.

http://msdn.microsof...v=vs.80%29.aspx

### #3KulSeran  Members

Posted 16 January 2011 - 10:51 AM

You could use a trick like boost::staticassert to cause a compile to die due to specific compile time checks. If your library has a header with your library define then you could do

// lib.h
#define LIB_BRAND (2)

#define BRAND (1)
BOOST_STATIC_ASSERT( BRAND == LIB_BRAND);

and have it properly break because the two brands aren't in fact the same.

### #4KulSeran  Members

Posted 16 January 2011 - 10:53 AM

-- aparently we can't delete our posts anymore --- removed doublepost

### #5Zbychs  Members

Posted 16 January 2011 - 01:06 PM

Thanks guys. Nice solutions.
Unfortunately KulSeran's solution won't work for me, since both defines have the same name. This cannot be changed.

I'll go with Adam's solution. I'd like to put it in one header common to both library and application - but for that I guess I'll need some kind of pragma to force reference for a "marker" symbol in application. Plus compiling lib with additional option -DCREATE_BRAND_MARKER to create the marek in lib.

I'll post here if I'll figure it out.

Thanks.

### #6Zbychs  Members

Posted 16 January 2011 - 05:13 PM

Here's my solution. One should put it in a header included in both lib and app. Library should be compiled with COMPILING_LIBRARY defined.
It generates link-time errors (unresolved external symbol '__marker_symbol_BRAND_0') when linking library and application compiled with different options:

#if defined(COMPILING_LIBRARY)
#if (BRAND == 0)
extern "C" void _marker_symbol_BRAND_0();
#else
extern "C" void _marker_symbol_BRAND_1();
#endif
#else
#if (BRAND == 0)
#else
#endif
#endif


Any comments? Maybe there are some side effects of using "#pragma comment?

Zbyl

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.