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 header only way #1511

Closed
chengm349 opened this issue Apr 10, 2020 · 9 comments
Closed

How to use header only way #1511

chengm349 opened this issue Apr 10, 2020 · 9 comments

Comments

@chengm349
Copy link

I did not use -DSPDLOG_COMPILED_LIB, but include spdlog header files path.

I got these link error:

/fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/format.h:877: undefined reference to fmt::v6::internal::assert_fail(char const*, int, char const*)' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function char* fmt::v6::internal::format_decimal<unsigned int, char, char* fmt::v6::internal::format_decimal<char, char*, unsigned int>(char*, unsigned int, int)::{lambda(char*)#1}>(char* fmt::v6::internal::format_decimal<char, char*, unsigned int>(char*, unsigned int, int)::{lambda(char*)#1}, unsigned int, int, char* fmt::v6::internal::format_decimal<char, char*, unsigned int>(char*, unsigned int, int)::{lambda(char*)#1})':
/fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/format.h:843: undefined reference to fmt::v6::internal::assert_fail(char const*, int, char const*)' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function endl(FtSpdlogDebugStream&)':
/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:60: undefined reference to spdlog::default_logger()' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function endl(FtSpdlogTraceStream&)':
/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:40: undefined reference to spdlog::default_logger()' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function endl(FtSpdlogCriticalStream&)':
/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:142: undefined reference to spdlog::default_logger()' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function endl(FtSpdlogErrorStream&)':
/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:122: undefined reference to spdlog::default_logger()' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function endl(FtSpdlogWarnStream&)':
/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:101: undefined reference to spdlog::default_logger()' /fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o):/fs02/home/thirdparty/spdlog2/include/FtSpdlogStream.h:81: more undefined references to spdlog::default_logger()' follow
/fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::internal::buffer<char> >, char>::on_error(char const*)': /fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/core.h:1169: undefined reference to fmt::v6::internal::error_handler::on_error(char const*)'
/fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function unsigned long long fmt::v6::internal::width_checker<fmt::v6::internal::error_handler>::operator()<float, 0>(float)': /fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/format.h:1988: undefined reference to fmt::v6::internal::error_handler::on_error(char const*)'
/fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function unsigned long long fmt::v6::internal::precision_checker<fmt::v6::internal::error_handler>::operator()<float, 0>(float)': /fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/format.h:2008: undefined reference to fmt::v6::internal::error_handler::on_error(char const*)'
/fs02/home/jenkins/workspace/Rel-15-1-0_PROD/Rel-15-1-54_c++14/directfeeds/face/AS7/libface.a(FtSpdFileLog.o): In function std::make_unsigned<int>::type fmt::v6::internal::to_unsigned<int>(int)': /fs02/home/thirdparty/spdlog2/include/spdlog/fmt/bundled/core.h:266: undefined reference to fmt::v6::internal::assert_fail(char const*, int, char const*)'
collect2: error: ld returned 1 exit status

my program coredumps when use SPDLOG_COMPILED_LIB. I want to try header files only.

@tt4g
Copy link
Contributor

tt4g commented Apr 10, 2020

If you are using spdlog with more than one library, make sure the version and build options match exactly.

In addition, if you link the static library in the wrong order, a link error will occur.

@chengm349
Copy link
Author

this time, I just want to try header files only. why still error in linking stage? or I should still link some sub-libs although no need of whole libspdlog.a?

@tt4g
Copy link
Contributor

tt4g commented Apr 10, 2020

For link errors, libface.a appears in the message.
Looking at the Makefile in this comment #1509 (comment), libface.a looked like a library, not an application.

Therefore, I determined that you linked multiple static libraries to your application and the build failed. Is this wrong?

@chengm349
Copy link
Author

thank you very much. you are right that I also linked the static lib for libface.a in its makefile. Now it's ok and no coredump. Same whole project code that if i use static lib, it will crash. very strange. Just that the header file only almost double my exe size compared with static way.

@chengm349
Copy link
Author

and I am very sure my project only links spdlog static lib once because of this HEADER file only check.

@chengm349
Copy link
Author

in fact, initially I used header file only way and my code ran ok. Later I downloaded new version of spdlog and tried static way, then immediately crashed as reported. Now I use our old logging method and my code is running ok. I have some time now so trying to see how can I use spdlog's static method.

@chengm349
Copy link
Author

it seems that signal function is happy with header file only mood.

@tt4g
Copy link
Contributor

tt4g commented Apr 12, 2020

As noted above (#1511 (comment)), spdlog is not guaranteed to work with signal functions. This is a move based on the C++ standard.

@chengm349
Copy link
Author

understood. I just feedback the difference btw header-only and static lib modes.

@gabime gabime closed this as completed Apr 20, 2020
bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
 (gabime#1511)

Co-authored-by: Lalit Kumar Bhasin <labhas@microsoft.com>
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

3 participants