2010-10-20 16 views
2
#include <string> 
#include <tr1/regex> 

#include "TextProcessing.h" 

const std::string URL_PATTERN("((http://)[[email protected]:%_\\+.~#?&//=]+)"); 
const std::string REPLACEMENT("<a href=\"$&\"\">$&</a>"); 

std::string textprocessing::processLinks(const std::string & text) 
{ 

    // essentially the same regex as in the previous example, but using a dynamic regex 
    std::tr1::regex url(URL_PATTERN); 

    // As in Perl, $& is a reference to the sub-string that matched the regex 
    return std::tr1::regex_replace(text, url, REPLACEMENT); 
} 

J'utilise mingw gcc copiler version 4.5.0.erreur lors de l'utilisation de la fonction regex_replace de <tr1/regex>

J'ai l'erreur de suivi:

%DEV%> mingw32-make all 
g++ -Wl,--enable-auto-import -Wall -Wextra -std=c++0x -pedantic -Werror -c -I./include TextProcessing.cpp 
cc1plus.exe: warnings being treated as errors 
c:\dev\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/tr1_impl/regex:2390:5: error: inline function '_Out_iter std::tr1::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, const std::basic_string<_Ch_type>&, std::tr1::regex_constants::match_flag_type) [with _Out_iter = std::back_insert_iterator<std::basic_string<char> >, _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, _Rx_traits = std::tr1::regex_traits<char>, _Ch_type = char, std::tr1::regex_constants::match_flag_type = std::bitset<11u>]' used but never defined 
mingw32-make: *** [TextProcessing.o] Error 1 
Process mingw32-make exited with code 2 
+0

Duplicates http://stackoverflow.com/questions/2860722/linker-error-when-using-tr1regex et http://stackoverflow.com/questions/2398994/link-tr1-on-ubuntu. –

Répondre

1

Eh oui, dans mon g ++ inclure des fichiers que je vois aussi que regex_replace est déclarée et non définie. Pour moi, c'est dans le fichier /usr/include/c++/4.4.4/tr1_impl/regex. Juste au-dessus de la déclaration est une section commentaire Doxygen qui comprend:

/** @todo Implement this function. */ 
1

Votre bibliothèque C++ standard ne prend pas en charge complète C++ 0x (maintenant C++ 1x?). Essayez d'utiliser le code de Boost. Voir aussi this answer.