2

我正在使用 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。并且有两个文件:

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 上工作得很好)?

4

0 回答 0