Chr*_*ris 4 c++ gcc compiler-errors g++ compiler-warnings
我正在尝试通过KIT 编译Contraction Hierarchies Implementation.
该软件已于2009年发布,从那以后显然没有得到维护.由于一些事情在平均时间内发生了变化(使用新的C++标准和编译器版本),代码不再编译.
在编写指令时,README并不是非常冗长,并且说你应该只调用它make
.但是,使用make会给我以下错误:
g++ -Wall -W -Wno-unused-parameter -O6 -c -o main.o main.cpp In file included from /usr/include/c++/4.8/ext/hash_map:60:0, from command/../io/../datastr/graph/../../io/serialize.h:26, from command/../io/../datastr/graph/edge.h:26, from command/../io/../datastr/graph/graph.h:59, from command/../io/createGraph.h:28, from command/NodeOrder.h:29, from main.cpp:35: /usr/include/c++/4.8/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp] #warning \ ^ command/../processing/../EliminationWeight.h:42:35: error: a call to a constructor cannot appear in a constant-expression static const Type MAX_VALUE = __DBL_MAX__; ^ command/../processing/../EliminationWeight.h:43:36: error: a call to a constructor cannot appear in a constant-expression static const Type MIN_VALUE = -__DBL_MAX__; ^ make: *** [main.o] Error 1
我需要做些什么才能进行编译?
要使软件编译没有错误,需要执行几个步骤.我用gcc 4.8.1和Boost 1.53.0测试了这些指令.
(我已经在那里详细回答了这个子问题,但会重复这里的重要步骤.)
我们遇到的第一个编译错误是由于软件使用GCC编译器的非标准扩展.似乎在软件开发时,这些不必由编译器开关启用,但现代GCC需要这样做.但是,为了将来的兼容性,我们将摆脱它们并以标准兼容的方式实现这些功能.
编译器告诉我们问题出在第42和43行EliminationWeight.h
.这些是该文件中的行:
static const Type MAX_VALUE = __DBL_MAX__;
static const Type MIN_VALUE = -__DBL_MAX__;
Run Code Online (Sandbox Code Playgroud)
GCC在这里抱怨,因为标准不涵盖类体中双打的初始化.相反,我们应该分开做.因此,删除初始化并将行更改为以下内容:
static const Type MAX_VALUE;
static const Type MIN_VALUE;
Run Code Online (Sandbox Code Playgroud)
同时删除#include <limits>
我们不再需要的文件.
由于我们仍然想要初始化这些值,我们来看看main.cpp
并找到第84行及以下内容:
// doesn't look nice, but required by the compiler (gcc 4)
const EdgeWeight Weight::MAX_VALUE;
const EliminationWeight::Type EliminationWeight::MAX_VALUE;
const EliminationWeight::Type EliminationWeight::MIN_VALUE;
Run Code Online (Sandbox Code Playgroud)
这看起来是进行初始化的最佳位置.更改第86行和第87行以包含以下代码:
const EliminationWeight::Type EliminationWeight::MAX_VALUE = std::numeric_limits< EliminationWeight::Type >::max();
const EliminationWeight::Type EliminationWeight::MIN_VALUE = -std::numeric_limits< EliminationWeight::Type >::max();
Run Code Online (Sandbox Code Playgroud)
还添加
#include <limits>
Run Code Online (Sandbox Code Playgroud)
对main.cpp
,因为我们现在使用的std::numeric_limits
从头类.
编译现在可以正常工作,但链接将失败并出现巨大的错误消息.(我已经在那里讨论了这个问题,但在这里将重复它的要点.)
所有错误都将与Boost :: Regex的链接有关.这是我机器上的完整错误消息:
g++ -lboost_regex -lboost_iostreams -o main main.o main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::unwind_extra_block(bool)': main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb]+0x2c): undefined reference to `boost::re_detail::put_mem_block(void*)' main.o: In function `void boost::re_detail::raise_error > > >(boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type)': main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0x7d): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)' main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xb1): undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)' main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xcb): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)' main.o: In function `__gnu_cxx::__normal_iterator boost::re_detail::re_is_set_member, char, boost::regex_traits >, unsigned int>(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, boost::re_detail::re_set_long const*, boost::re_detail::regex_data > > const&, bool)': main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x17b): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const' main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x4c0): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform(char const*, char const*) const' main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::extend_stack()': main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv]+0x18): undefined reference to `boost::re_detail::get_mem_block()' main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_imp()': main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0xc): undefined reference to `boost::re_detail::get_mem_block()' main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x19e): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)' main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x254): undefined reference to `boost::re_detail::put_mem_block(void*)' main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x3c6): undefined reference to `boost::re_detail::put_mem_block(void*)' main.o: In function `bool boost::regex_match, std::allocator, std::allocator > >, char, boost::regex_traits > >(std::basic_string, std::allocator > const&, boost::match_results, std::allocator >::const_iterator, std::allocator > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags)': main.cpp:(.text._ZN5boost11regex_matchISt11char_traitsIcESaIcESaINS_9sub_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEEEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbRKSbIT2_T_T0_ERNS_13match_resultsINSJ_14const_iteratorET1_EERKNS_11basic_regexISG_T3_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchISt11char_traitsIcESaIcESaINS_9sub_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEEEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbRKSbIT2_T_T0_ERNS_13match_resultsINSJ_14const_iteratorET1_EERKNS_11basic_regexISG_T3_EENS_15regex_constants12_match_flagsE]+0xe9): undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)' main.o: In function `void Command::createVector(std::string const&, std::vector >&, double)': main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x4a): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x7b): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xac): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' main.o: In function `void Command::createVector(std::string const&, std::vector >&, unsigned int)': main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x48): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x79): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' main.o:main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xaa): more undefined references to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' follow main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_match()': main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE11match_matchEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE11match_matchEv]+0x371): undefined reference to `boost::match_results, std::allocator > > >::maybe_assign(boost::match_results, std::allocator > > > const&)' main.o: In function `boost::re_detail::perl_matcher, std::allocator > >, boost::regex_traits > >::match_dot_repeat_slow()': main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE21match_dot_repeat_slowEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE21match_dot_repeat_slowEv]+0x229): undefined reference to `boost::re_detail::get_mem_block()' collect2: error: ld returned 1 exit status make: *** [main] Error 1
似乎根本找不到Boost :: Regex.请注意,这是需要编译并链接到您的应用程序才能工作的Boost库之一.以下是假设您已获得编译版本并且它位于系统的库目录中.
链接时,库和目标文件通过命令行参数传递给GCC的顺序非常重要.出于某些原因,2009年与海湾合作委员会合作的现在已不再适用.这可以通过更改make
将参数传递给GCC 的顺序来解决.
找到Makefile
项目根目录并找到第6行:
$(CXX) $(LINK) -o $@ $^ $(LIBS)
Run Code Online (Sandbox Code Playgroud)
在这里,您可以看到make
在目标文件之前传递包含Boost库的链接器开关.(如果你不能,请不要担心.你不必理解Makefile遵循这个解释.)为了使这个工作与当前的GCC,我们将改变参数的顺序.你的第6行Makefile
应该是这样的:
$(CXX) -o $@ $^ $(LIBS) $(LINK)
Run Code Online (Sandbox Code Playgroud)
保存并make
再次运行.编译和链接现在应该没有错误地进行.
您仍会看到编译器警告,告诉您正在使用已弃用的头文件.您可以忽略此警告.但是,可能有更新版本的GCC没有附带此头文件,编译将失败.
如果你想解决它,这是如何.
问题在于io/serialize.h
包括哪些内容<ext/hash_map>
.C++ 11标准取代了它unordered_map
.所以我们修改代码来使用它.第128行将是
typedef __gnu_cxx::hash_map<key_type, data_type> HashMap;
Run Code Online (Sandbox Code Playgroud)
将此更改为使用unordered_map
如下:
typedef std::unordered_map<key_type, data_type> HashMap;
Run Code Online (Sandbox Code Playgroud)
现在我们还需要修复标题.删除包含<ext/hash_map>
并替换第26行
#include <algorithm>
#include <unordered_map>
Run Code Online (Sandbox Code Playgroud)
将<algorithm>
需要包括因为很明显,<ext/hash_map>
还提供std::sort
和std::reverse
为hash_map
.这些函数现在位于<algorithm>
标题中,代码依赖于此文件包含这些函数的事实.
由于这是一个C++ 11特性,我们需要告诉GCC我们需要支持.转到compiler.make
项目的根目录,找到应该是的第6行
CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER)
Run Code Online (Sandbox Code Playgroud)
在该行的末尾添加开关以使用C++ 11:
CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER) -std=c++11
Run Code Online (Sandbox Code Playgroud)
再次运行make clean
,make
您的代码应该编译,没有任何错误或警告.
归档时间: |
|
查看次数: |
737 次 |
最近记录: |