Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) undefined reference to 'boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'

 

link error.

 

 

 

 

 

Full error message

 

/MyFolder/main.o:: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
/usr/include/boost/regex/v4/basic_regex.hpp:425: error: undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
:: error: collect2: ld returned 1 exit status

 

 

 

 

 

Cause

 

Operating system: Ubuntu 10.04 Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: Console Application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

 

Qt project file

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-08-06T13:56:29
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = CppRegexExample1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

 

 

 

 

 

Source code

 

#include <boost/regex.hpp>

int main()
{
  const boost::regex dutch_zip_code("[a-zA-z]{4}\\d{2}");
}

 

 

 

 

 

Solution

 

Add the following line to the Qt Creator project file:

 

LIBS += -L/usr/local/lib -lboost_regex

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict