私は ming64 (gcc 4.5.4) を使用しており、テスト プログラムは次のようになります。
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <boost/program_options.hpp>
#include <boost/program_options/detail/config_file.hpp>
int main()
{
std::ifstream ifs("");
std::map<std::string, std::string> parameters;
std::set<std::string> options;
for (boost::program_options::detail::config_file_iterator i(ifs, options, true), e; i != e; ++i)
{
parameters[i->string_key] = i->value[0];
}
return 0;
}
コンパイルすると、次のようになります。
Linking CXX executable main.exe
CMakeFiles\main.dir/objects.a(main.cpp.obj): In function `basic_config_file_iterator':
C:/Users/test/Desktop/po/src/include/boost/program_options/detail/config_file.hpp:147: undefined reference to `boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool)'
C:/Users/test/Desktop/po/src/include/boost/program_options/detail/config_file.hpp:150: undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
CMakeFiles\main.dir/objects.a(main.cpp.obj): In function `boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >::increment()':
C:/Users/test/Desktop/po/src/include/boost/program_options/eof_iterator.hpp:75: undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
collect2: ld returned 1 exit status
mingw32-make[2]: *** [main.exe] Error 1
mingw32-make[1]: *** [CMakeFiles/main.dir/all] Error 2
mingw32-make: *** [all] Error 2
と をリンクし-Lpath_to_lib
ます-llibboost_program_options-mgw45-mt-1_48
。そして、次の 2 つのファイルがあります。
libboost_program_options-mgw45-mt-1_48.dll libboost_program_options-mgw45-mt-1_48.dll.a
nm は、ライブラリに対して次の出力を提供します。
$ nm libboost_program_options-mgw45-mt-1_48.dll|grep common_config_file_iterator
000000006395e0a0 d .data$_ZTIN5boost12eof_iteratorINS_15program_options6detail27common_config_file_iteratorENS1_12basic_optionIcEEEE
000000006395e0c0 d .data$_ZTIN5boost15iterator_facadeINS_15program_options6detail27common_config_file_iteratorEKNS1_12basic_optionIcEENS_21forward_traversal_tag
ERS6_xEE
000000006395e440 d .data$_ZTIN5boost15program_options6detail27common_config_file_iteratorE
000000006395f6a0 d .data$_ZTVN5boost15program_options6detail27common_config_file_iteratorE
0000000063962d60 r .rdata$_ZTSN5boost12eof_iteratorINS_15program_options6detail27common_config_file_iteratorENS1_12basic_optionIcEEEE
0000000063962de0 r .rdata$_ZTSN5boost15iterator_facadeINS_15program_options6detail27common_config_file_iteratorEKNS1_12basic_optionIcEENS_21forward_traversal_ta
gERS6_xEE
0000000063963560 r .rdata$_ZTSN5boost15program_options6detail27common_config_file_iteratorE
0000000063933ce0 t .text$_ZN5boost15program_options6detail27common_config_file_iterator7getlineERSs
0000000063933cf0 t .text$_ZN5boost15program_options6detail27common_config_file_iteratorD0Ev
0000000063933ec0 t .text$_ZN5boost15program_options6detail27common_config_file_iteratorD1Ev
0000000063934080 t .text$_ZN5boost15program_options6detail27common_config_file_iteratorD2Ev
00000000639100a0 t _GLOBAL__I__ZN5boost15program_options6detail27common_config_file_iteratorC2ERKSt3setISsSt4lessISsESaISsEEb
000000006390da90 T _ZN5boost15program_options6detail27common_config_file_iterator10add_optionEPKc
000000006390e6d0 T _ZN5boost15program_options6detail27common_config_file_iterator3getEv
U _ZN5boost15program_options6detail27common_config_file_iterator7getlineERSs
0000000063933ce0 T _ZN5boost15program_options6detail27common_config_file_iterator7getlineERSs
000000006390e3f0 T _ZN5boost15program_options6detail27common_config_file_iteratorC1ERKSt3setISsSt4lessISsESaISsEEb
000000006390e3f0 T _ZN5boost15program_options6detail27common_config_file_iteratorC2ERKSt3setISsSt4lessISsESaISsEEb
U _ZN5boost15program_options6detail27common_config_file_iteratorD0Ev
0000000063933cf0 T _ZN5boost15program_options6detail27common_config_file_iteratorD0Ev
U _ZN5boost15program_options6detail27common_config_file_iteratorD1Ev
0000000063933ec0 T _ZN5boost15program_options6detail27common_config_file_iteratorD1Ev
0000000063934080 T _ZN5boost15program_options6detail27common_config_file_iteratorD2Ev
000000006390d900 T _ZNK5boost15program_options6detail27common_config_file_iterator14allowed_optionERKSs
000000006395e0a0 D _ZTIN5boost12eof_iteratorINS_15program_options6detail27common_config_file_iteratorENS1_12basic_optionIcEEEE
000000006395e0c0 D _ZTIN5boost15iterator_facadeINS_15program_options6detail27common_config_file_iteratorEKNS1_12basic_optionIcEENS_21forward_traversal_tagERS6_x
EE
000000006395e440 D _ZTIN5boost15program_options6detail27common_config_file_iteratorE
0000000063962d60 R _ZTSN5boost12eof_iteratorINS_15program_options6detail27common_config_file_iteratorENS1_12basic_optionIcEEEE
0000000063962de0 R _ZTSN5boost15iterator_facadeINS_15program_options6detail27common_config_file_iteratorEKNS1_12basic_optionIcEENS_21forward_traversal_tagERS6_x
EE
0000000063963560 R _ZTSN5boost15program_options6detail27common_config_file_iteratorE
000000006395f6a0 D _ZTVN5boost15program_options6detail27common_config_file_iteratorE
未定義の参照の原因は何ですか (同じコードが Linux でも問題なく動作します)。