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

unresolved external symbol when using a string_view inside a REQUIRE #2605

Closed
famastefano opened this issue Dec 27, 2022 · 4 comments
Closed

Comments

@famastefano
Copy link

Describe the bug
If I try to link my tests that contain a REQUIRE clause with a string_view, I got this linker error:

LNK2019	unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Catch::StringMaker<class std::basic_string_view<char,struct std::char_traits<char> >,void>::convert(class std::basic_string_view<char,struct std::char_traits<char> >)" (?convert@?$StringMaker@V?$basic_string_view@DU?$char_traits@D@std@@@std@@X@Catch@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string_view@DU?$char_traits@D@std@@@4@@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Catch::Detail::stringify<class std::basic_string_view<char,struct std::char_traits<char> > >(class std::basic_string_view<char,struct std::char_traits<char> > const &)" (??$stringify@V?$basic_string_view@DU?$char_traits@D@std@@@std@@@Detail@Catch@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$basic_string_view@DU?$char_traits@D@std@@@3@@Z)

Expected behavior
I expect to link without problems.

Reproduction steps

std::string_view view = "test";
std::string string = "test";
REQUIRE(view == string);

Platform information:

  • OS: Windows 10 Pro 19045.2364
  • Compiler+version:
    Microsoft Visual Studio Professional 2022 (64-bit) - LTSC 17.2 Version 17.2.10
    MSCV 19.32.31335
  • Catch version: v3.2.1 (via Conan Center)

Additional context
I don't know if it's Conan or something that happened to Catch, but my tests didn't have this problem months ago.
Now that I've migrated from vcpkg to Conan, this problem showed up.
At the moment I don't have time to provide a minimum example nor to check a previous version of Catch.
I'll try in my free time after work, but it means a lot of hours :P

@famastefano
Copy link
Author

Added a minimum reproducible example:
catch-issue-2605.zip

To compile:

> conan install . --build=missing
> cmake configure . --preset='default'
> cmake --build --preset=release

The presets are the one generated by conan.
In my case the default profile builds for Release, but the problem persists for Debug builds also.

@famastefano
Copy link
Author

On Linux, specifically WSL2, Ubuntu 24.04 LTS:

cmake --build --preset debug
[  0%] Built target stl_companion_lib
[ 12%] Building CXX object test/CMakeFiles/test_stl_companion.dir/test_main.cpp.o
[ 25%] Building CXX object test/CMakeFiles/test_stl_companion.dir/algorithm/test_string_search.cpp.o
[ 37%] Building CXX object test/CMakeFiles/test_stl_companion.dir/algorithm/test_container_search.cpp.o
[ 50%] Building CXX object test/CMakeFiles/test_stl_companion.dir/string/test_string_trim.cpp.o
[ 62%] Building CXX object test/CMakeFiles/test_stl_companion.dir/string/test_string_split.cpp.o
[ 75%] Building CXX object test/CMakeFiles/test_stl_companion.dir/string/test_string_join.cpp.o
[ 87%] Building CXX object test/CMakeFiles/test_stl_companion.dir/math/test_math_map.cpp.o
[100%] Linking CXX executable test_stl_companion
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23
CMakeFiles/test_stl_companion.dir/string/test_string_split.cpp.o: in function `std::string Catch::Detail::stringify<std::basic_string_view<char, std::char_traits<char> > >(std::basic_string_view<char, std::char_traits<char> > const&)':
test_string_split.cpp:(.text._ZN5Catch6Detail9stringifyISt17basic_string_viewIcSt11char_traitsIcEEEESsRKT_[_ZN5Catch6Detail9stringifyISt17basic_string_viewIcSt11char_traitsIcEEEESsRKT_]+0x36): undefined reference to `Catch::StringMaker<std::basic_string_view<char, std::char_traits<char> >, void>::convert(std::basic_string_view<char, std::char_traits<char> >)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [test/CMakeFiles/test_stl_companion.dir/build.make:194: test/test_stl_companion] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:154: test/CMakeFiles/test_stl_companion.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

@vsaulue
Copy link
Contributor

vsaulue commented Jan 31, 2023

I had the same issue with MSVC. It happened because Conan was building Catch2's static libraries with /std:c++14 (the current default for MSVC). This causes StringMaker<std::string_view>::convert(std::string_view) to not be included in the binary.

Note: clang currently also defaults to c++14.

Fix

Make sure to specify the c++ standard of your project in the conan install command by setting compiler.cppstd. Conan will use it to build the dependencies, instead of the compiler's default standard.

Directly on the command line:

# For c++20 projects
conan install .. --build=missing -s compiler.cppstd=20

Or add compiler.cppstd=__ in the Conan profile used to build your project.

More info: Conan: How to manage C++ standard

@famastefano
Copy link
Author

Sorry, didn't use my personal GitHub since ages.
Thanks for the reply!

I'm stunned of discovering this behaviour of conan, the first thing I'll do on monday will be to update all my recipes!

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

No branches or pull requests

3 participants