sustrik / libdill

Structured concurrency in C
MIT License
1.68k stars 155 forks source link

Conflicts with STL: it redefines the macro 'now' that is defined in the STL's header 'chrono' #181

Closed yurivict closed 5 years ago

yurivict commented 5 years ago

I tried to use libdill in a C++ program that uses STL and found that it conflicts with STL.

When libdill.h is included before STL, it compiles but then link fails:

tmp/main-0f5fc5.o: In function `main':
main.cpp:(.text+0x18c3): undefined reference to `std::__1::chrono::system_clock::dill_now()'
/tmp/main-0f5fc5.o: In function `_GLOBAL__sub_I_main.cpp':
main.cpp:(.text+0x2ef3): undefined reference to `std::__1::chrono::system_clock::dill_now()'

When libdill.h is included after STL, compilation fails:

main.cpp:403:37: error: no member named 'dill_now' in 'std::__1::chrono::system_clock'
         std::chrono::system_clock::now().time_since_epoch().count()
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/libdill.h:95:13: note: expanded from macro 'now'
#define now dill_now
            ^

C can be (arguably) viewed as a subset of C++, and can normally be used from inside C++, and STL is a common C++ library.

You should probably consider using some namespace specifier, for ex. dill_, with every name it defines.

yurivict commented 5 years ago

Sorry, I found that there is a workaround for this: DILL_DISABLE_RAW_NAMES.