用g ++链接问题

时间:2015-08-20 10:07:30

标签: c++ boost

我正在使用C ++ boost库编写代码,我收到链接错误 -

代码

#include "test/support/checkers/log-entry-presence-checkers.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>   
#include <boost/test/unit_test.hpp>

using namespace std;


namespace YumaTest
{
LogEntryPresenceChecker::LogEntryPresenceChecker(
    const vector<string>& expPresentText )
: checkStrings_( expPresentText )
{
}
LogEntryPresenceChecker::~LogEntryPresenceChecker()
{
}
void LogEntryPresenceChecker::operator()( const string& logFilePath ) const
{
     ifstream logFile;
     string line;
bool entryFound;

BOOST_FOREACH ( const string& val, checkStrings_ )
{
    entryFound = false;
    BOOST_TEST_MESSAGE( "\tChecking " << val << " is present" );
    logFile.open( logFilePath );
    if (logFile.is_open()) {
         while ( logFile.good() && entryFound == false ) {
            getline(logFile, line);
            if ( line.find( val ) != string::npos ) {
                entryFound = true;
            }
        }
        logFile.close();
    }
    BOOST_CHECK_EQUAL( true, entryFound );
}
}

链接错误 -

 g++ output/b64.o output/bobhash.o output/cap.o output/cfg.o output/cli.o output/conf.o output/def_reg.o output/dlq.o output/ext.o output/grp.o output/help.o output/json_wr.o output/log.o output/ncx_appinfo.o output/ncx.o output/ncx_feature.o output/ncx_list.o output/ncxmod.o output/ncx_num.o output/ncx_str.o output/obj.o output/obj_help.o output/op.o output/plock.o output/plock_cb.o output/rpc.o output/rpc_err.o output/runstack.o output/ses.o output/ses_msg.o output/status.o output/tk.o output/top.o output/tstamp.o output/typ.o output/val.o output/val_util.o output/var.o output/xml_msg.o output/xmlns.o output/xml_util.o output/xml_val.o output/xml_wr.o output/xpath1.o output/xpath.o output/xpath_wr.o output/xpath_yang.o output/yang.o output/yang_ext.o output/yang_grp.o output/yang_obj.o output/yang_parse.o output/yang_typ.o output/yin.o output/yinyang.o output/send_buff.o output/agt_acm.o output/agt.o output/agt_cap.o output/agt_cb.o output/agt_cfg.o output/agt_cli.o output/agt_commit_complete.o output/agt_connect.o output/agt_hello.o output/agt_if.o output/agt_ncx.o output/agt_not.o output/agt_plock.o output/agt_proc.o output/agt_rpc.o output/agt_rpcerr.o output/agt_ses.o output/agt_signal.o output/agt_state.o output/agt_sys.o output/agt_time_filter.o output/agt_timer.o output/agt_top.o output/agt_tree.o output/agt_util.o output/agt_val.o output/agt_val_parse.o output/agt_xml.o output/agt_xpath.o output/agt_yuma_arp.o output/agt_ncxserver.o output/checker-group.o output/string-presence-checkers.o output/log-entry-presence-checkers.o output/sil-callback-log.o output/callback-checker.o output/sil-callback-controller.o output/device-test-db.o output/device-test-db-debug.o output/state-data-test-db.o output/abstract-nc-session.o output/nc-base-query-test-engine.o output/nc-default-operation-config.o output/nc-query-test-engine.o output/nc-query-utils.o output/nc-strings.o output/yuma-op-policies.o output/abstract-global-fixture.o output/test-context.o output/base-suite-fixture.o output/query-suite-fixture.o output/simple-container-module-fixture.o output/simple-yang-fixture.o output/device-module-fixture.o output/device-get-module-fixture.o output/device-module-common-fixture.o output/state-get-module-fixture.o output/state-data-module-common-fixture.o output/cpp-unit-op-formatter.o output/log-utils.o output/ptree-utils.o output/base64.o output/NCMessageBuilder.o output/xpo-query-builder.o output/state-data-query-builder.o output/spoof-nc-session.o output/spoof-nc-session-factory.o output/running-cb-checker.o output/candidate-cb-checker.o output/integ-cb-checker-factory.o output/integ-fixture-helper.o output/integ-fixture-helper-factory.o output/simple-edit-tests.o output/default-none-tests.o output/simple-edit-running.o -Wall -g -lxml2 -lboost_unit_test_framework -Wl,--export-dynamic -o test-simple-edit-running
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:52: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryNonPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:89: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::concatenateLogFiles()':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:66: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::appendLog(std::basic_ofstream<char, std::char_traits<char> >&, unsigned short)':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:84: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
collect2: ld returned 1 exit status

我不明白为什么会出现未定义引用的错误。

请帮帮我怎样才能解决这个问题。

先谢谢。

1 个答案:

答案 0 :(得分:2)

您是否从某处复制/粘贴了目标文件或库文件?它们必须针对相同的二进制接口构建。

这看起来非常类似于你使用的是C ++ 11头文件而是一个C ++ 03运行时,因为你的编译代码希望找到 Language Constructs mean the basic constructs of a programming languge e.g 1. Conditions (if, else, switch) 2. Loops (For, While, Do-while) etc 构造函数重载ifstream(在C +中引入) +11),但链接器无法找到实现此类重载的证据。

使用相同的工具链重建包括Boost库在内的所有内容,看看会发生什么。