Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use it without boost? #110

Open
Jenuce opened this issue Aug 30, 2018 · 8 comments
Open

how to use it without boost? #110

Jenuce opened this issue Aug 30, 2018 · 8 comments

Comments

@Jenuce
Copy link

Jenuce commented Aug 30, 2018

boost is very big, why not do not depend on it?

@mfontanini
Copy link
Owner

I guess given C++17 has std::any and std::optional which are the 2 things currently being used by cppkafka, we could optionally allow using these features from namespace std rather than boost, but you'll need access to C++17 (or later).

@accelerated
Copy link
Contributor

accelerated commented Sep 26, 2018

it could be opted out at compile time with

#if (__cplusplus >= 201703L)
... use std
#else 
... boost
#endif

I actually think this would be a good PR

@mfontanini
Copy link
Owner

This should actually go into the config.h file so that if you build the library, then you must use whatever you used while building. Otherwise you could build cppkafka using some compiler on C++14 (using boost), then you build your application using C++17 and link against the C++14 .so and then your code will go kaboom.

@accelerated
Copy link
Contributor

accelerated commented Sep 26, 2018

You can actually catch this error at link time and prevent linking to mismatched libraries even w/o a config file or cmake flags.

//in the public cppkafka .h file
#if (__cpluplus >= 201703L)
extern int CPPKAFKA_COMPILED_STL;
static const int MY_LIBRARY_VERSION = CPPKAFKA_COMPILED_STL;
... stl include headers
#else
extern int CPPKAFKA_COMPILED_BOOST;
static const int MY_LIBRARY_VERSION = CPPKAFKA_COMPILED_BOOST;
... boost include headers
#endif

// inside any cppkafka .cpp file
#if (__cpluplus >= 201703L)
int CPPKAFKA_COMPILED_STL;
#else
int CPPKAFKA_COMPILED_BOOST;
#endif

Now if the cppkafka library was built with a c++11 compiler and the app with c++17, the app won't link as CPPKAFKA_COMPILED_STL is not defined. Same technique can be used to tag ABI incompatible versions.

@mfontanini
Copy link
Owner

If you build the library on C++14 and use boost, then you use C++17 on your application and you're using boost then you want this to build as it can do that just fine. I wouldn't expect my code to fail to build if I build in C++17 when the library was built using C++14.

@accelerated
Copy link
Contributor

The code above was an example...instead of using #defines on the compiler version it can simply be a #define USE_BOOST which in turn could be set in the cmake file. Or a combination of both.
Point being that past c++17, it's hard to justify the added dependency on boost.

@marcoippolito
Copy link

Could it be "fixed" adding these options in the cmake file within the next release?

@sekarpdkt
Copy link

Any luck with this. I would like to keep it without boost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants