Bonjour,

je souhaite utiliser la librairie regex de cette page : http://www.cplusplus.com/reference/s...egex_iterator/
J'utilise la dernière version en date de MinGW et MSys.
Par contre je n'arrive pas à compiler l'exemple donné et je débute avec les makefiles.

Voici le code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// regex_iterator constructor
#include <iostream>
#include <string>
#include <regex>
 
int main ()
{
  std::string s ("this subject has a submarine as a subsequence");
  std::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"
 
  std::regex_iterator<std::string::iterator> rit ( s.begin(), s.end(), e );
  std::regex_iterator<std::string::iterator> rend;
 
  while (rit!=rend) {
    std::cout << rit->str() << std::endl;
    ++rit;
  }
 
  return 0;
}
Mon makefile :
Code :
1
2
3
4
main.o: 	
	gcc -c Main.cpp -std=c++11
main.exe:	main.o
	gcc -o main.exe main.o -std=c++11
Ci-dessous les erreurs tronquées :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
main.o:Main.cpp:(.text+0x74): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
main.o:Main.cpp:(.text+0xab): undefined reference to `std::allocator<char>::allocator()'
main.o:Main.cpp:(.text+0xc3): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.o:Main.cpp:(.text+0xd0): undefined reference to `std::allocator<char>::~allocator()'
main.o:Main.cpp:(.text+0xf6): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::end()'
main.o:Main.cpp:(.text+0x102): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::begin()'
main.o:Main.cpp:(.text+0x124): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> >::regex_iterator(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
main.o:Main.cpp:(.text+0x131): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> >::regex_iterator()'
main.o:Main.cpp:(.text+0x13d): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> >::operator->()'
main.o:Main.cpp:(.text+0x165): undefined reference to `std::cout'
main.o:Main.cpp:(.text+0x16a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.o:Main.cpp:(.text+0x171): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main.o:Main.cpp:(.text+0x178): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
main.o:Main.cpp:(.text+0x185): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.o:Main.cpp:(.text+0x18f): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> >::operator++()'
main.o:Main.cpp:(.text+0x19f): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> >::operator!=(std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::regex_traits<char> > const&)'
Que dois je modifier dans mon Makefile pour prendre en compte la librairie regex ?

Merci.