#How do I let the end user select which library features get compiled?

5 messages · Page 1 of 1 (latest)

odd zodiac
#

I have a library that creates a very large static lookup table (>80KB). I want to give the end user the option to trim the size of the lookup table to about 10KB at the cost of some performance. I don’t want to create two separate libraries. What is the idiomatic way to do this? Would something like this be appropriate? ```cpp
#include <my_lib.h>

#define FAVOR_SIZE // defined by default

int main() {
mylib::func(); // func uses the smaller lookup table
}``````cpp
#include <my_lib.h>

#define FAVOR_SPEED

int main() {
mylib::func(); // func uses the faster lookup table
}``````cpp
#include <my_lib.h>

#define FAVOR_SIZE
#define FAVOR_SPEED

int main() {
mylib::func(); // unsure how to handle this situation yet
}```This feels like a very messy solution with a handful of edge cases, is there a standard way of handling this sort of thing?

sage compassBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

blazing aspen
#

Macro definitions are the common way.

odd zodiac
#

Good to know! I’ve only ever personally seen this come up in an OpenGL supplementary library so I didn’t know if it was just a bad practice or something

#

!solved