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

Link error when HAS_STRING_VIEW is defined #398

Open
DorfilIkatu opened this issue Oct 9, 2018 · 4 comments
Open

Link error when HAS_STRING_VIEW is defined #398

DorfilIkatu opened this issue Oct 9, 2018 · 4 comments
Labels

Comments

@DorfilIkatu
Copy link

Hi,

I was trying to build an example using libtz.so, and I got an "undefined reference" error.

Following is the code of my example:

#include <iostream>
#include "date/date.h"
#include "date/tz.h"

using namespace std;
using namespace date;

int main()
{
    auto t = make_zoned("Europe/London", chrono::system_clock::now());
    cout << t << endl;
   return 0;
}

The link error:

 "[...] undefined reference to `date::locate_zone(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'"

When I run nm command on libtz.so to check that locate_zone symbol was there, I got:

0001198c T date::locate_zone(std::basic_string_view<char, std::char_traits<char> >)
000081fc T date::tzdb::locate_zone(std::basic_string_view<char, std::char_traits<char> >) const 

The result I got indicates that the library was compiled with HAS_STRING_VIEW=1, while the linker was trying to find the function version that is built when HAS_STRING_VIEW=0.

After this I set HAS_STRING_VIEW=0 and built everything again, and this time the build was successful.

I'm not calling locate_zone directly, it is being called inside the library itself so, is it possible that this is a bug of the library and not an error on my example?

Thanks

@HowardHinnant
Copy link
Owner

It may be a cmake bug, but I am not sure. I am not fluent in cmake and don't use it for myself. Others are maintaining it. I just always include src/tz.cpp in my build and don't bother making it into a separate library, and so my flags don't have an opportunity to differ between tz.cpp and the clients of tz.cpp.

@lkolda
Copy link

lkolda commented Jan 17, 2019

This should not be an excuse to provide a working version. I can not use it because it can't be added as DorfilIkatu said.

@emptyVoid
Copy link

emptyVoid commented May 17, 2019

I'm facing the same issue with vcpkg as the package manager on Windows. For date it does not set CMAKE_CXX_STANDARD, and VC++ 2019 defaults to C++14, while my code is compiled under C++17.

In my opinion the API should at least be backward-compatible, proving const time_zone* locate_zone(const std::string& tz_name); under C++17 too. Or even better -- the internal API could be in plain C.

@degski
Copy link

degski commented Aug 8, 2019

This is still a problem, compiling with C++17 results in locate_zone undefined linking errors (on Windows). Compiling the .cpp file into the project is not a good solution.

EDIT: I've opened #7591 on vcpkg and added a quick fix, the port is simply in-complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants