ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
521 stars 82 forks source link

How can I get it header only? #99

Closed DynamicLoader closed 2 years ago

DynamicLoader commented 2 years ago

Hi,

I am trying to use this library in my project.I just need to use the Reader and Writer APIs,and C++11,C99 is supported.

I'd like to make it header only so that no compile command is needed to be changed.But it reported a lot of errors of conflicting definations.

All I have done is include the two files in my single header file and modify the config to disable builder,expect and node.

Thanks.

ludocode commented 2 years ago

If you want it to be "header only" you can include the .c file, i.e. #include mpack/mpack.c, in one translation unit only (i.e. one other .c or .cpp file.) This is in fact how I use it in one of my projects. If you include it in multiple translation units then you'll get linking errors due to duplicate definitions.

I'm assuming since you closed this issue that you got it working? Feel free to reopen if you're still having problems.