Dev C++ with boost regex

Hello all,

I have the following code, which is an example from boost:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 *
 * Copyright (c) 1998-2002
 * Dr John Maddock
 *
 * Use, modification and distribution are subject to the 
 * Boost Software License, Version 1.0. (See accompanying file 
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 *
 */

 /*
  *   LOCATION:    see http://www.boost.org for most recent version.
  *   FILE         credit_card_example.cpp
  *   VERSION      see <boost/version.hpp>
  *   DESCRIPTION: Credit card number formatting code.
  */

#include <string>
#include <boost/regex.hpp>

bool validate_card_format(const std::string& s)
{
   static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
   return boost::regex_match(s, e);
}

const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
const std::string machine_format("\\1\\2\\3\\4");
const std::string human_format("\\1-\\2-\\3-\\4");

std::string machine_readable_card_number(const std::string& s)
{
   return boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed);
}

std::string human_readable_card_number(const std::string& s)
{
   return boost::regex_replace(s, e, human_format, boost::match_default | boost::format_sed);
}

#include <iostream>
using namespace std;

int main()
{
   string s[4] = { "0000111122223333", "0000 1111 2222 3333",
                   "0000-1111-2222-3333", "000-1111-2222-3333", };
   int i;
   for(i = 0; i < 4; ++i)
   {
      cout << "validate_card_format(\"" << s[i] << "\") returned " << validate_card_format(s[i]) << endl;
   }
   for(i = 0; i < 4; ++i)
   {
      cout << "machine_readable_card_number(\"" << s[i] << "\") returned " << machine_readable_card_number(s[i]) << endl;
   }
   for(i = 0; i < 4; ++i)
   {
      cout << "human_readable_card_number(\"" << s[i] << "\") returned " << human_readable_card_number(s[i]) << endl;
   }
   return 0;
}


But, when i try to compile, i get the following error:

1
2
3
4
5
6
C:\Users\diegog\Documents\DEV\teste_2\main.o	main.cpp:(.text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[__ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0x23): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
C:\Users\diegog\Documents\DEV\teste_2\main.o	main.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEj[__ZN5boost9re_detail11raw_storage6extendEj]+0x46): undefined reference to `boost::re_detail::raw_storage::resize(unsigned int)'
c:\program files\dev-cpp\mingw32\mingw32\bin\ld.exe	main.o: bad reloc address 0x46 in section `.text$_ZN5boost9re_detail11raw_storage6extendEj[__ZN5boost9re_detail11raw_storage6extendEj]'
c:\program files\dev-cpp\mingw32\mingw32\bin\ld.exe	final link failed: Invalid operation
C:\Users\diegog\Documents\DEV\teste_2\collect2.exe	[Error] ld returned 1 exit status
25		C:\Users\diegog\Documents\DEV\teste_2\Makefile.win	recipe for target 'Project1.exe' failed 


I've added the regex library to the compiler, but i dont know what to do about the makefile (if the problem is in there).
Im using Dev C++ 5.5.3 and Windows 7. Any ideas?
I've added the regex library to the compiler, but i dont know what to do about the makefile (if the problem is in there).

This looks like a linker error.

It may be caused by the fact that the library object file isn't compatible with the linker. So perhaps you chose the wrong object file (that wasn't meant for GCC)?

If I were you, I'd prefer using Visual Studio 2013 Express, which implements the regex library of C++11.

http://www.cplusplus.com/reference/regex/

This way you won't have to worry about using third party libraries, just because GCC doesn't implement standard regex yet. And when the GCC team finally implements C++11 regex, your code will compile unmodified!
I was afraid Dev C++ linker wasnt compatible with boost :(

Ill try it with Visual Studio soon, thanks for the help !
I was afraid Dev C++ linker wasnt compatible with boost :(


This is not true. Just compile boost yourself using the same compiler/linker and it will work.
Topic archived. No new replies allowed.