Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to execute below program. It is building fine but am getting 2 linker errors:
Kindly help me.
C++
#include <iostream>
#include <iterator>
#include <regex>
#include <string>
//#define BOOST_REGEX_DYN_LINK

using namespace std;
 
int main()
{
   std::string text = "Quick brown fox";
   std::regex vowel_re1("a|e|i|o|u");

 
   // write the results to an output iterator
   std::regex_replace(std::ostreambuf_iterator<char>(std::cout),
                      text.begin(), text.end(), vowel_re1, "*");
 
   // construct a string holding the results
   std::cout << '\n' << std::regex_replace(text, vowel_re1, "[$&]") << '\n';
}

Linker errors:
myClient.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct>,class std::allocator<char> > __cdecl std::tr1::regex_replace<class>,char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct>,class std::allocator<char> > const &,class std::tr1::basic_regex<char,class> > const &,char const *,enum std::tr1::regex_constants::match_flag_type)" (??$regex_replace@V?$regex_traits@D@tr1@std@@DU?$char_traits@D@3@V?$allocator@D@3@@tr1@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@ABV21@ABV?$basic_regex@DV?$regex_traits@D@tr1@std@@@01@PBDW4match_flag_type@regex_constants@01@@Z) referenced in function _main
1>myClient.obj : error LNK2019: unresolved external symbol "class std::ostreambuf_iterator<char,struct> > __cdecl std::tr1::regex_replace<class> >,class std::_String_iterator<char,struct>,class std::allocator<char> >,class std::tr1::regex_traits<char>,char>(class std::ostreambuf_iterator<char,struct> >,class std::_String_iterator<char,struct>,class std::allocator<char> >,class std::_String_iterator<char,struct>,class std::allocator<char> >,class std::tr1::basic_regex<char,class> > const &,char const *,enum std::tr1::regex_constants::match_flag_type)" (??$regex_replace@V?$ostreambuf_iterator@DU?$char_traits@D@std@@@std@@V?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@V?$regex_traits@D@tr1@2@D@tr1@std@@YA?AV?$ostreambuf_iterator@DU?$char_traits@D@std@@@1@V21@V?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@1@1ABV?$basic_regex@DV?$regex_traits@D@tr1@std@@@01@PBDW4match_flag_type@regex_constants@01@@Z) referenced in function _main
1>C:\Users\smallesh\Documents\Visual Studio 2010\Projects\C#\Client\Debug\Client.exe : fatal error LNK1120: 2 unresolved externals
Posted
Updated 19-Aug-13 20:27pm
v7
Comments
Maarten Kools 19-Aug-13 11:04am    
Have you included the lib in the linker settings? If so, is the search path correct?
shivareaj 20-Aug-13 1:45am    
Many thanks for your reply.

I don't have idea on which lib file to include in linker settings.
Please guide.
Richard MacCutchan 19-Aug-13 11:27am    
That code would not even compile, since all your #include statements are incorrect.
shivareaj 20-Aug-13 1:49am    
Sorry i could write symbols <, > as it was interpreted some other . Please add those symbols in #include while you compiling.
It is sure that there is no build errors.
Richard MacCutchan 20-Aug-13 2:30am    
If you format your code blocks properly by putting in between <pre> tags, or use the code link above the edit box, then all characters will be shown correctly, as I have done to your post.

As to your problem, when I build that code (in VC++ 2010 Express) the only problem is a compile time error on regex_replace. Comment that out and it links correctly. You must have a directory path missing from your linker properties.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900