Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > С/С++: Кроссплатформенное программирование, Qt/Gtk+/wxWidgets > Qt + boost.regex ошибка линковки


Автор: CaLaT 17.6.2011, 18:51
Добрый день!

Нужда в реализации парсера поддтолкнула на приобщение к высокому... а именно boost.regex
Однако столкнулся с проблемой компановки (ошибки ниже), судя по всему компилятор не может найти нужный lib, вот только не могу понять какой и, собственно, где в pro-файле нужно его указать (путь до буста и собранных библиотек вроде указываю же).

Pro-file
Код

QT       += core
QT       -= gui
INCLUDEPATH += \
    C:/Soft/boost/boost_1_46_1 \
    C:/Soft/boost/boost_1_46_1/stage/lib
TARGET = CppHelloBoost
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp


main.cpp
Код

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

int main()
{
  std::string s = "Hello World";
  s = boost::regex_replace(s,boost::regex("World"),std::string("Boost"));
  std::cout << s << '\n';
}



(!) Тот самый список ошибок при компиляции 
Код

debug/main.o: In function `cpp_regex_traits_char_layer':
c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:366: undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/regex_raw_buffer.hpp:131: undefined reference to `boost::re_detail::raw_storage::resize(unsigned int)'
debug/main.o: In function `save_state_init':
c:/Soft/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:107: undefined reference to `boost::re_detail::get_mem_block()'
debug/main.o: In function `~save_state_init':
c:/Soft/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:115: undefined reference to `boost::re_detail::put_mem_block(void*)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/perl_matcher_common.hpp:292: undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:218: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::raise() const'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_parser.hpp:219: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:795: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:796: undefined reference to `boost::regex_error::raise() const'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:796: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:796: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:877: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:878: undefined reference to `boost::regex_error::raise() const'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:878: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:878: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:942: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:943: undefined reference to `boost::regex_error::raise() const'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:943: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:943: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1133: undefined reference to `boost::regex_error::regex_error(std::string const&, boost::regex_constants::error_type, int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1134: undefined reference to `boost::regex_error::raise() const'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1134: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:1134: undefined reference to `boost::regex_error::~regex_error()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:442: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:444: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/basic_regex_creator.hpp:320: undefined reference to `boost::re_detail::raw_storage::insert(unsigned int, unsigned int)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:1117: undefined reference to `boost::re_detail::put_mem_block(void*)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/pattern_except.hpp:75: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:66: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:75: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/pending/object_cache.hpp:75: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:625: undefined reference to `boost::re_detail::lookup_default_collate_name(std::string const&)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/perl_matcher_non_recursive.hpp:213: undefined reference to `boost::re_detail::get_mem_block()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:667: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:682: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1051: undefined reference to `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1054: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
debug/main.o:c:/Soft/boost/boost_1_46_1/boost/regex/v4/cpp_regex_traits.hpp:1054: undefined reference to `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug/CppHelloBoost.exe] Error 1
mingw32-make.exe[1]: Leaving directory `D:/My_Docs/!Progs/!Training/Boost_Regex2'
mingw32-make.exe: *** [debug] Error 2


В аттаче qt проект с кодом.

Буду рад любым советам и предложениям!

Добавлено @ 18:58
Собственно пример проекта взят от http://www.richelbilderbeek.nl/CppHelloBoostQtCreatorWindows.htm

И в pro-файле указывается интересный момент:
Цитата

win32:LIBS +=C:/Qt/2010.02.1/qt/lib/libboost_regex.lib

Судя по путям, в qt/lib попросту собран boost. У меня они лежат в дефолтном boost/boost_1_46_1/stage/lib , но у меня нет "libboost_regex.lib" и в памине
Прилинковка существующих:
(libboost_regex-vc100-mt.lib)
(libboost_regex-vc100-mt-1_46_1.lib)
(libboost_regex-vc100-mt-gd.lib)
(libboost_regex-vc100-mt-gd-1_46_1.lib)
не дала результата

Автор: Cheloveck 17.6.2011, 20:06
Код

LIBS += -Lpath/to/boost/lib -lboost_regex


Добавлено через 2 минуты и 16 секунд
Да, если уже есть Qt, зачем ещё зависимости тянуть? http://doc.qt.nokia.com/latest/qregexp.html

Автор: borisbn 17.6.2011, 21:05
Поддержива Cheloveck'а - зачем буст, если есть QRegExp ?

Автор: CaLaT 18.6.2011, 00:13
Цитата(Cheloveck @ 17.6.2011,  20:06)
Код

LIBS += -Lpath/to/boost/lib -lboost_regex

Если я не ошибаюсь, то это решение для linux платформы
Сам виноват, что явно не указал. Но мне нужно для win32

p.s. планируется более широкое использоваие буста для написания отдельных модулей, дело одними регулярками не ограничится.

Автор: Cheloveck 18.6.2011, 00:55
Цитата(CaLaT @  18.6.2011,  00:13 Найти цитируемый пост)
Если я не ошибаюсь, то это решение для linux платформы

Цитата

You can use the Unix -l (library) and -L (library path) flags and qmake will do the correct thing with these libraries on Windows and the Symbian platform

http://doc.qt.nokia.com/latest/qmake-variable-reference.html#libs

Автор: CaLaT 18.6.2011, 10:51
Собственно теперь ошибка:
Код

mingw32-make.exe -f Makefile.Debug
mingw32-make.exe[1]: Entering directory `D:/My_Docs/!Progs/!Training/Boost_Regex2'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug/CppHelloBoost.exe debug/main.o  -L'C:/Soft/boost/boost_1_46_1/stage/lib' -lboost_regex -L'c:/Soft/Qt/2010.05/qt/lib' -lQtCored4
c:/soft/qt/2010.05/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lboost_regex
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug/CppHelloBoost.exe] Error 1
mingw32-make.exe[1]: Leaving directory `D:/My_Docs/!Progs/!Training/Boost_Regex2'
mingw32-make.exe: *** [debug] Error 2


И только сейчас заметил, что в именах собранных либов у меня везде libboost_...-vc100-....lib, что мне намекнуло
Похоже, что на машине некогда стояла MSVS10 и bjam решил, что она стоит до сих пор и будет являться моим основным тулсетом... 

Попробую пересобрать буст. О результатах опишусь

Автор: Cheloveck 18.6.2011, 13:55
CaLaT, в -l не пишешь префикс lib и постфикс .lib, остальную часть имени библиотеки пишешь, включаея vc100

Автор: CaLaT 19.6.2011, 12:15
Цитата(CaLaT @ 18.6.2011,  10:51)
Похоже, что на машине некогда стояла MSVS10 и bjam решил, что она стоит до сих пор и будет являться моим основным тулсетом... 

Попробую пересобрать буст. О результатах опишусь

Таки да. Пересобрав буст всё заработало.
Код

bjam.exe toolset=gcc --build-type=complete stage

 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)