estraier / tkrzw

a set of implementations of DBM
Apache License 2.0
164 stars 20 forks source link

Is it possible to build statically? #1

Closed maiha closed 4 years ago

maiha commented 4 years ago

Compilation with --enable-static --disable-shared fails.

$ ./configure --enable-static --disable-shared

$ make
(...snip...)
g++ -g -O2 -std=c++17 -Wall -fPIC -fsigned-char -g0 -O2 -o tkrzw_build_util tkrzw_build_util.o -L. -L/usr/local/lib -L/usr/local/lib -Wl,-rpath-link,.:/usr/local/lib:.:/usr/local/lib: -Wl,--as-needed -L. -L/usr/local/lib -L/usr/local/lib -static -ltkrzw -lstdc++ -lrt -lpthread -lm -lc  -lstdc++ -lrt -lpthread -lm -lc

/usr/bin/ld: ./libtkrzw.a(tkrzw_cmd_util.o): in function `tkrzw::FileIndex::Iterator::Iterator(std::unique_ptr<tkrzw::DBM::Iterator, std::default_delete<tkrzw::DBM::Iterator> >)':
tkrzw_cmd_util.cc:(.text+0x160): multiple definition of `tkrzw::FileIndex::Iterator::Iterator(std::unique_ptr<tkrzw::DBM::Iterator, std::default_delete<tkrzw::DBM::Iterator> >)'; tkrzw_build_util.o:tkrzw_build_util.cc:(.text+0x180): first defined here
/usr/bin/ld: ./libtkrzw.a(tkrzw_cmd_util.o): in function `tkrzw::FileIndex::Iterator::Iterator(std::unique_ptr<tkrzw::DBM::Iterator, std::default_delete<tkrzw::DBM::Iterator> >)':
(...snip...)
collect2: error: ld returned 1 exit status
make: *** [Makefile:602: tkrzw_build_util] Error 1

Best regards,

estraier commented 4 years ago

Thanks for pointing it out. I'd forgotten to add "inline" modifiers. I pushed the fix. However, there's another problem with the static linking; Pthread doesn't work with static linking. I'm looking for a solution now.

maiha commented 4 years ago

Yep! It worked with master!

$ make
$ ldd ./tkrzw_dbm_util
        not a dynamic executable

I'm also looking forward to supporting pthreads for the static link version. Thank you very much.

estraier commented 4 years ago

I fixed the issue for pthread static linking. It's been already pushed. Now, you can run "make check" even with "configure --enable-static".

maiha commented 4 years ago

You work fast! And great job! ㊗️ 💯 👍

lumina7 commented 4 years ago

Sorry to be of topic. @maiha, Is a crystal client for tkrzw coming?

The successor of tokyocabinet/kyotocabinet is here, dreams do come true after all!!! :) Christmas is early this year.

maiha commented 4 years ago

Hi @lumina7 Yep, that's the plan. For now, I just created the repository. 😄 https://github.com/maiha/tkrzw.cr

pfalcon commented 3 years ago

Pthread doesn't work with static linking.

Did you consider making pthread support optional in the first place?

estraier commented 3 years ago

Pthread is supported by default. The issue discussed here was to do static linking. Somehow, the Pthread library cannot be linked statically. Thus, we need some tweaks to exclude it from the range of static linking.

On Sun, Dec 20, 2020 at 2:35 AM Paul Sokolovsky notifications@github.com wrote:

Pthread doesn't work with static linking.

Did you consider making pthread support optional in the first place?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/estraier/tkrzw/issues/1#issuecomment-748502499, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQGJVREUSUU3XX2ICHPZBD3SVTP57ANCNFSM4PAW3KBQ .

kostya commented 2 years ago

btw, why static library so big? 80Mb. and like + ~30Mb for binary which liked it. May be it links some unnesessary things?

estraier commented 2 years ago

The total size of *.o of Tkrzw is 80MB. So, probably, the large size is due to the compiler, not the linker. du -bch tkrzw_lib_common.o tkrzw_str_util.o tkrzw_hash_util.o tkrzw_time_util.o tkrzw_compress.o tkrzw_file_util.o tkrzw_file_std.o tkrzw_file_mmap.o tkrzw_file_pos.o tkrzw_file_poly.o tkrzw_message_queue.o tkrzw_dbm.o tkrzw_dbm_ulog.o tkrzw_dbm_common_impl.o tkrzw_dbm_hash_impl.o tkrzw_dbm_hash.o tkrzw_dbm_tree_impl.o tkrzw_dbm_tree.o tkrzw_dbm_skip_impl.o tkrzw_dbm_skip.o tkrzw_dbm_tiny.o tkrzw_dbm_baby.o tkrzw_dbm_cache.o tkrzw_dbm_std.o tkrzw_dbm_poly.o tkrzw_dbm_shard.o tkrzw_dbm_async.o tkrzw_cmd_util.o tkrzw_langc.o

The reasons why the object files are so big are various. Using STL extensively is one of them. Using -Os is effective to reduce the size. Another way is to make a mini library by selecting some object files which are necessary to specific use cases. However, maintaining them would be painstaking.

On Sun, Jan 16, 2022 at 9:21 PM Kostya M @.***> wrote:

btw, why static library so big? 80Mb. and like + ~30Mb for binary which liked it. May be it links some unnesessary things?

— Reply to this email directly, view it on GitHub https://github.com/estraier/tkrzw/issues/1#issuecomment-1013865864, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQGJVRBTR2SLOQGJSEI5LYDUWKZ3VANCNFSM4PAW3KBQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>