[CMake] [cmake-developers] C++11/C++14 doesn't work in check_cxx_source_compiles
Roman Wüger
roman.wueger at gmx.at
Thu Nov 24 13:43:20 EST 2016
It is working now, after I added -lc++ to CMAKE_REQUIRED_LIBRARIES before the check_cxx_source_compiles() call.
Shouldn't this be done by CMAKE_CXX_STANDARD?
Best Regards
Roman
> Am 24.11.2016 um 19:08 schrieb Roman Wüger <roman.wueger at gmx.at>:
>
> Hello,
>
> If I use a small piece of code which uses <regex>, then it fails with check_cxx_source_compiles. If I copy the piece of code into a file and run the following on the command line, then it works:
>
> clang++ main.cpp -std=c++14 -stdlib=libc++
>
> Here is the piece of code:
>
> #include <regex>
> #include <string>
>
> int main() {
> const std::string text = "Roses are #ff0000, other flowers have other colors.";
> const std::regex pattern("#([a-f0-9]{2})");
>
> std::smatch match;
> std::regex_search(text, match, pattern);
>
> return 0;
> }
>
> I use this code in CMake as a platform check as followed:
>
> # C++11 Regular Expression
> set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
> check_cxx_source_compiles(
> "#include <regex>
> #include <string>
>
> int main() {
> const std::string text = \"Roses are #ff0000, other flowers have other colors.\";
> const std::regex pattern(\"#([a-f0-9]{2})\");
>
> std::smatch match;
> std::regex_search(text, match, pattern);
>
> return 0;
> }"
> HAVE_CXX11_REGULAR_EXPRESSIONS
> )
> set(CMAKE_REQUIRED_FLAGS "")
>
> CMakeFiles/CMakeError.log shows:
>
> Undefined symbols for architecture x86_64:
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in src.o
> "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
> std::__1::vector<std::__1::sub_match<char const*>, std::__1::allocator<std::__1::sub_match<char const*> > >::assign(unsigned long, std::__1::sub_match<char const*> const&) in src.o
> std::__1::vector<std::__1::sub_match<char const*>, std::__1::allocator<std::__1::sub_match<char const*> > >::allocate(unsigned long) in src.o
> void std::__1::vector<std::__1::__state<char>, std::__1::allocator<std::__1::__state<char> > >::__push_back_slow_path<std::__1::__state<char> >(std::__1::__state<char>&&) in src.o
> std::__1::vector<std::__1::sub_match<char const*>, std::__1::allocator<std::__1::sub_match<char const*> > >::__append(unsigned long, std::__1::sub_match<char const*> const&) in src.o
> std::__1::vector<std::__1::pair<unsigned long, char const*>, std::__1::allocator<std::__1::pair<unsigned long, char const*> > >::__append(unsigned long) in src.o
> std::__1::vector<std::__1::pair<unsigned long, char const*>, std::__1::allocator<std::__1::pair<unsigned long, char const*> > >::allocate(unsigned long) in src.o
> void std::__1::vector<char, std::__1::allocator<char> >::__push_back_slow_path<char>(char&&) in src.o
> ...
> "std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
> std::__1::enable_if<__is_forward_iterator<char*>::value, void>::type std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init<char*>(char*, char*) in src.o
> std::__1::enable_if<__is_forward_iterator<char const*>::value, void>::type std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init<char const*>(char const*, char const*) in src.o
> std::__1::enable_if<__is_forward_iterator<std::__1::__wrap_iter<char*> >::value, void>::type std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init<std::__1::__wrap_iter<char*> >(std::__1::__wrap_iter<char*>, std::__1::__wrap_iter<char*>) in src.o
> "std::__1::__match_any_but_newline<char>::__exec(std::__1::__state<char>&) const", referenced from:
> vtable for std::__1::__match_any_but_newline<char> in src.o
> "std::__1::locale::name() const", referenced from:
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in src.o
> "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
> std::__1::regex_traits<char>::__init() in src.o
> "std::__1::regex_error::regex_error(std::__1::regex_constants::error_type)", referenced from:
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_basic_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_extended_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_assertion<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_atom<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ERE_dupl_symbol<char const*>(char const*, char const*, std::__1::__owns_one_state<char>*, unsigned int, unsigned int) in src.o
> bool std::__1::basic_regex<char, std::__1::regex_traits<char> >::__match_at_start_ecma<std::__1::allocator<std::__1::sub_match<char const*> > >(char const*, char const*, std::__1::match_results<char const*, std::__1::allocator<std::__1::sub_match<char const*> > >&, std::__1::regex_constants::match_flag_type, bool) const in src.o
> ...
> "std::__1::regex_error::~regex_error()", referenced from:
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_basic_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_extended_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_assertion<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_atom<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ERE_dupl_symbol<char const*>(char const*, char const*, std::__1::__owns_one_state<char>*, unsigned int, unsigned int) in src.o
> bool std::__1::basic_regex<char, std::__1::regex_traits<char> >::__match_at_start_ecma<std::__1::allocator<std::__1::sub_match<char const*> > >(char const*, char const*, std::__1::match_results<char const*, std::__1::allocator<std::__1::sub_match<char const*> > >&, std::__1::regex_constants::match_flag_type, bool) const in src.o
> ...
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
> _main in src.o
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:
> std::__1::__bracket_expression<char, std::__1::regex_traits<char> >::__exec(std::__1::__state<char>&) const in src.o
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char*>(char*, char*, char) const in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_collating_symbol<char const*>(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in src.o
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in src.o
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_equivalence_class<char const*>(char const*, char const*, std::__1::__bracket_expression<char, std::__1::regex_traits<char> >*) in src.o
> void std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::__push_back_slow_path<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in src.o
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
> _main in src.o
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in src.o
> std::__1::__bracket_expression<char, std::__1::regex_traits<char> >::__exec(std::__1::__state<char>&) const in src.o
> std::__1::__vector_base<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::~__vector_base() in src.o
> std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::~pair() in src.o
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::transform<char*>(char*, char*) const in src.o
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char*>(char*, char*, char) const in src.o
> ...
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char*>(char*, char*, char) const in src.o
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in src.o
> "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(char)", referenced from:
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_character_escape<char const*>(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_expression_term<char const*>(char const*, char const*, std::__1::__bracket_expression<char, std::__1::regex_traits<char> >*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_class_escape<char const*>(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::__bracket_expression<char, std::__1::regex_traits<char> >*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_awk_escape<char const*>(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) in src.o
> "std::__1::__get_classname(char const*, bool)", referenced from:
> unsigned int std::__1::regex_traits<char>::__lookup_classname<char const*>(char const*, char const*, bool, char) const in src.o
> "std::__1::__shared_weak_count::__add_shared()", referenced from:
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::basic_regex(std::__1::basic_regex<char, std::__1::regex_traits<char> > const&) in src.o
> "std::__1::__shared_weak_count::__release_shared()", referenced from:
> std::__1::shared_ptr<std::__1::__empty_state<char> >::~shared_ptr() in src.o
> "std::__1::__shared_weak_count::~__shared_weak_count()", referenced from:
> std::__1::__shared_ptr_pointer<std::__1::__empty_state<char>*, std::__1::default_delete<std::__1::__empty_state<char> >, std::__1::allocator<std::__1::__empty_state<char> > >::~__shared_ptr_pointer() in src.o
> "std::__1::__get_collation_name(char const*)", referenced from:
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char*>(char*, char*, char) const in src.o
> std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in src.o
> "std::__1::ctype<char>::id", referenced from:
> std::__1::regex_traits<char>::__init() in src.o
> "std::__1::locale::locale(std::__1::locale const&)", referenced from:
> std::__1::regex_traits<char>::regex_traits(std::__1::regex_traits<char> const&) in src.o
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in src.o
> "std::__1::locale::locale()", referenced from:
> std::__1::regex_traits<char>::regex_traits() in src.o
> "std::__1::locale::~locale()", referenced from:
> std::__1::regex_traits<char>::~regex_traits() in src.o
> std::__1::regex_traits<char>::regex_traits() in src.o
> std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in src.o
> "std::__1::collate<char>::id", referenced from:
> std::__1::regex_traits<char>::__init() in src.o
> "typeinfo for std::__1::regex_error", referenced from:
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_basic_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_extended_reg_exp<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_assertion<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_atom<char const*>(char const*, char const*) in src.o
> char const* std::__1::basic_regex<char, std::__1::regex_traits<char> >::__parse_ERE_dupl_symbol<char const*>(char const*, char const*, std::__1::__owns_one_state<char>*, unsigned int, unsigned int) in src.o
> bool std::__1::basic_regex<char, std::__1::regex_traits<char> >::__match_at_start_ecma<std::__1::allocator<std::__1::sub_match<char const*> > >(char const*, char const*, std::__1::match_results<char const*, std::__1::allocator<std::__1::sub_match<char const*> > >&, std::__1::regex_constants::match_flag_type, bool) const in src.o
> ...
> "typeinfo for std::__1::__shared_weak_count", referenced from:
> typeinfo for std::__1::__shared_ptr_pointer<std::__1::__empty_state<char>*, std::__1::default_delete<std::__1::__empty_state<char> >, std::__1::allocator<std::__1::__empty_state<char> > > in src.o
> "vtable for std::__1::__shared_count", referenced from:
> std::__1::shared_ptr<std::__1::__empty_state<char> >::shared_ptr<std::__1::__empty_state<char> >(std::__1::__empty_state<char>*, std::__1::enable_if<is_convertible<std::__1::__empty_state<char>*, std::__1::__empty_state<char>*>::value, std::__1::shared_ptr<std::__1::__empty_state<char> >::__nat>::type) in src.o
> NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
> "vtable for std::__1::__shared_weak_count", referenced from:
> std::__1::shared_ptr<std::__1::__empty_state<char> >::shared_ptr<std::__1::__empty_state<char> >(std::__1::__empty_state<char>*, std::__1::enable_if<is_convertible<std::__1::__empty_state<char>*, std::__1::__empty_state<char>*>::value, std::__1::shared_ptr<std::__1::__empty_state<char> >::__nat>::type) in src.o
> NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>
> ** BUILD FAILED **
>
> Did I forget something?
>
> Thanks in advance
>
> Best Regards
> Roman
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161124/646d750a/attachment-0001.html>
More information about the CMake
mailing list