4

KIT による縮小階層の実装をコンパイルしようとしています。

このソフトウェアは 2009 年に公開され、それ以来メンテナンスされていません。その間にいくつかの変更があったため (新しい C++ 標準とコンパイラのバージョンで)、コードは既製のままではコンパイルされなくなりました。

README は、コンパイルに関する指示に関してはあまり冗長ではなく、make. ただし、make を使用すると、次のエラーが表示されます。

g++ -Wall -W -Wno-unused-parameter -O6 -c -o main.o main.cpp
/usr/include/c++/4.8/ext/hash_map:60:0 からインクルードされたファイルで、
                 コマンド/../io/../datastr/graph/../../io/serialize.h:26 から、
                 command/../io/../datastr/graph/edge.h:26 から、
                 command/../io/../datastr/graph/graph.h:59 から、
                 command/../io/createGraph.h:28 から、
                 コマンド/NodeOrder.h:29 から、
                 main.cpp:35 から:
/usr/include/c++/4.8/backward/backward_warning.h:32:2: 警告: #warning このファイルには、少なくとも 1 つの非推奨または時代遅れのヘッダーが含まれており、将来予告なしに削除される可能性があります。代わりに、同等の機能を持つ非推奨でないインターフェースを使用してください。置換ヘッダーとインターフェースのリストについては、backward_warning.h ファイルを参照してください。この警告を無効にするには、-Wno-deprecated を使用します。[-Wcpp]
 #警告 \
  ^
command/../processing/../EliminationWeight.h:42:35: エラー: コンストラクターの呼び出しは定数式に表示できません
     static const Type MAX_VALUE = __DBL_MAX__;
                                   ^
command/../processing/../EliminationWeight.h:43:36: エラー: コンストラクターの呼び出しを定数式に含めることはできません
     static const Type MIN_VALUE = -__DBL_MAX__;
                                    ^
make: *** [main.o] エラー 1

これをコンパイルするにはどうすればよいですか?

4

1 に答える 1

6

ソフトウェアをエラーなしでコンパイルするには、いくつかの手順が必要です。これらの命令を 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__;

クラス本体での double の初期化は標準でカバーされていないため、GCC はここで文句を言います。代わりに、個別に行う必要があります。したがって、初期化を削除して、行を次のように変更します。

static const Type MAX_VALUE;
static const Type MIN_VALUE;

#include <limits>このファイルでは不要になったので、も削除します。

これらの値を初期化する必要があるため、main.cpp84 行目以降を確認します。

// 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;

これは、初期化を行うのに最適な場所のようです。行 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();

また追加

#include <limits>

そのヘッダーmain.cppのクラスを使用しているためです。std::numeric_limits

collect2: エラー: ld が 1 つの終了ステータスを返しました

コンパイルは機能するようになりましたが、リンクは失敗して巨大なエラー メッセージが表示されます。(この問題については既に説明しましたが、ここで要点を繰り返します。)

すべてのエラーは、Boost::Regex のリンクに関するものです。これは、私のマシンの完全なエラー メッセージです。

g++ -lboost_regex -lboost_iostreams -o メイン main.o
main.o: 関数 `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: 関数 `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: 関数内 `__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: 関数 `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: 関数 `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: 関数内 `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: 関数 `void Command::createVector(std::string const&, std::vector >&, double)':
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x4a): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x7b): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照
main.cpp:(.text._ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xac): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照
main.o: 関数 `void Command::createVector(std::string const&, std::vector >&, unsigned int)':
main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x48): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照
main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0x79): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照
main.o:main.cpp:(.text._ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_[_ZN7Command12createVectorIjEEvRKSsRSt6vectorIT_SaIS4_EES4_]+0xaa): `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' への未定義の参照が続きます
main.o: 関数 `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: 関数 `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: エラー: ld が 1 つの終了ステータスを返しました
make: *** [メイン] エラー 1

Boost::Regex がまったく見つからないようです。これは、コンパイルしてアプリケーションにリンクする必要がある Boost ライブラリの 1 つです。以下は、コンパイルされたバージョンを入手し、それがシステムのライブラリ ディレクトリにあることを前提としています。

リンクするとき、ライブラリとオブジェクト ファイルがコマンド ライン パラメータを介して GCC に渡される順序が重要です。何らかの理由で、2009 年に GCC で動作していたように見えるものが、現在は動作していません。これはmake、パラメーターを GCC に渡す順序を変更することで修正できます。

Makefileプロジェクトのルート ディレクトリに移動し、6 行目を見つけます。

$(CXX) $(LINK) -o $@ $^ $(LIBS)

makeここでは、Boost ライブラリを含むリンカー スイッチをオブジェクト ファイルの前に渡していることがわかります。(できなくても心配しないでください。この説明に従うために Makefile を理解する必要はありません。) 現在の GCC でこれを機能させるために、パラメーターの順序を変更します。6 行目は次のMakefileようになります。

$(CXX) -o $@ $^ $(LIBS) $(LINK)

保存してmake再度実行してください。コンパイルとリンクはエラーなしで進行するはずです。

warning: #warning このファイルには非推奨または時代遅れのヘッダーが少なくとも 1 つ含まれています

非推奨のヘッダー ファイルを使用していることを示すコンパイラ警告が引き続き表示されます。この警告は無視してかまいません。ただし、GCC の新しいバージョンにはこのヘッダー ファイルが付属しておらず、コンパイルが失敗する可能性があります。

あなたがそれを修正したい場合は、ここに方法があります。

問題は、io/serialize.hwhich includesにあります<ext/hash_map>。C++11 標準では、これが に置き換えられunordered_mapます。そのため、それを使用するようにコードを修正します。128行目は

typedef __gnu_cxx::hash_map<key_type, data_type> HashMap;

これを変更して、次のように使用unordered_mapします。

typedef std::unordered_map<key_type, data_type> HashMap;

ここで、ヘッダーも修正する必要があります。インクルードを削除し、<ext/hash_map>26行目を次のように置き換えます

#include <algorithm>
#include <unordered_map>

<algorithm>明らかに<ext/hash_map>また提供さstd::sortstd::reverseているため、インクルードが必要ですhash_map。これらの関数は現在<algorithm>ヘッダーにあり、コードはこれらがこのファイルに含まれているという事実に依存しています。

これは C++11 の機能であるため、そのサポートが必要であることを GCC に伝える必要があります。プロジェクトのルート ディレクトリに移動しcompiler.make、6 行目を見つけます。

CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER)

行の最後に、C++11 を使用するためのスイッチを追加します。

CXXFLAGS = $(DEBUG) $(WARNING) $(OPTIMIZER) -std=c++11

何度も実行するmake cleanmake、コードはエラーや警告なしでコンパイルされるはずです。

于 2013-07-16T08:01:09.340 に答える