簡體   English   中英

G ++的鏈接器錯誤

[英]Linker error with g++

我使用以下命令編譯代碼:

g++ configuration_test.cpp -o configuration_test -lboost_unit_test_framework -I/root/target/include -ljsoncpp -L/root/target/lib/ -lboost_system -L/home/shubhada/Downloads/build/x86_64/lib -lconfiguration -L/home/shubhada/Downloads/build/x86_64/lib -ldbclient -L/home/shubhada/Downloads/build/x86_64/lib -ljsonparser -lboost_serialization

我的代碼是:

#include <boost/test/unit_test.hpp>
#include <string.h>
#include <iostream>
#include <istream>
#include <sstream>
#include <fstream>
#include <json/json.h> // To access members of Json Parser.
#include <json/value.h>
#include <json/reader.h>
#include <cstdlib>
#include <pthread.h>
#include <vector>
#include "../../include/Constant.h"
#include "../src/Configuration.h"
#include "../../transport-endpoint/src/TransportEndpoint.h"
#include "../../dbclient/src/DbClient.h"
#include "../../json-parser/src/JsonParser.h"

using namespace std;
using namespace Rubicon;

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE XXX_Service

BOOST_AUTO_TEST_SUITE(Configuration)
BOOST_AUTO_TEST_CASE(test_config_check_file_not_empty) {

    BOOST_TEST_MESSAGE( "test_config_check_file_not_empty begins");

    std::ostringstream buf;
    std::ifstream input ("sample.config.json");
    buf << input.rdbuf();
    std::string strConfigStr = buf.str();

    /*Check that the config file is not empty.*/
    BOOST_CHECK(strcmp(strConfigStr.c_str(),"") != 0);

    BOOST_TEST_MESSAGE("test_config_check_file_not_empty ends");
}

BOOST_AUTO_TEST_CASE(test_config_check_valid_json_str) {

    BOOST_TEST_MESSAGE( "test_config_check_valid_json_str begins");

    std::vector<Type> type;
    Json::ValueIterator jsonItrBegin, jsonItrEnd;

    std::ostringstream buf;
    std::ifstream input ("sample.config.json");
    buf << input.rdbuf();
    std::string strConfigStr = buf.str();

    Json::Reader jsonRead;
    Json::Value jsonValueRoot;

    /*Get the configuation object settings.*/
    odConfiguration *config = new odConfiguration();
    config->init(strConfigStr);

    /*Parse the configuration json string.*/
    jsonRead.parse(strConfigStr, jsonValueRoot, false);
    /*Check that the processor count is properly parsed.*/
    BOOST_CHECK(1 == config->getProcessorCount()); 
    /*Check that the worker count is properly parsed.*/
    BOOST_CHECK(1 == config->getWorkerCount());
    /*Check that data type is properly parsed.*/
    for (jsonItrBegin = jsonValueRoot.begin(), jsonItrEnd = jsonValueRoot.end(); jsonItrBegin != jsonItrEnd; ++jsonItrBegin) {
        if (strcmp("data-type", jsonItrBegin.memberName()) == 0) {
            for (unsigned i = 0; i < jsonItrBegin->size(); ++i) {
                const Json::Value & jsonVal = (*jsonItrBegin)[i];
                if(strcmp("tag", jsonVal.asCString()) == 0) {
                    type.push_back(TAG);
                } else if(strcmp("metatopic", jsonVal.asCString()) == 0) {
                    type.push_back(METATOPIC);
                } else if(strcmp("topic", jsonVal.asCString()) == 0) {
                    type.push_back(TOPIC);
                } else if(strcmp("classification", jsonVal.asCString()) == 0) {
                    type.push_back(CLASSIFICATION);
                }
            }
            /*Check that the data type is parsed properly.*/
            BOOST_CHECK(type == config->getDataType());
        }
    }
    BOOST_TEST_MESSAGE("test_config_check_valid_json_str ends");
}

BOOST_AUTO_TEST_CASE(test_transport_endpoint_config_check_valid_json_str) {

    BOOST_TEST_MESSAGE( "test_transport_endpoint_config_check_valid_json_str begins");

    std::ostringstream buf;
    std::ifstream input ("sample.config.json");
    buf << input.rdbuf();
    std::string strConfigStr = buf.str();

    /* Get the configuration object settings.*/
    odConfiguration *config = new odConfiguration();
    config->init(strConfigStr);

    odTransportEndpointConfig transportEndpointConfig = config->getTransportEndpointConfig();

    /*Check that the transport endpoint implementation is properly parsed.*/ 
    BOOST_CHECK(XYZ == transportEndpointConfig.getImpl());
    /*Check that the transport endpoint type is properly parsed.*/
    BOOST_CHECK(TE_SUBCRIBER == transportEndpointConfig.getType());
    /*Check that the transport endpoint uri is properly parsed.*/
    BOOST_CHECK(strcmp("tcp://127.0.0.1:8888", (transportEndpointConfig.getUri()).c_str())==0);
    /*Check that the transport endpoint topic is properly parsed.*/
    BOOST_CHECK(strcmp("XXX", (transportEndpointConfig.getTopic()).c_str())==0);
    BOOST_TEST_MESSAGE("test_transport_endpoint_config_check_valid_json_str ends");
}


BOOST_AUTO_TEST_CASE(test_db_client_config_check_valid_json_str) {

    BOOST_TEST_MESSAGE( "test_db_client_config_check_valid_json_str begins");

    std::ostringstream buf;
    std::ifstream input ("sample.config.json");
    buf << input.rdbuf();
    std::string strConfigStr = buf.str();

    odConfiguration *config = new odConfiguration();
    config->init(strConfigStr);

    /*Get the db client config from the configuration object*/
    odDbClientConfig dbClientConfig = config->getDbClientConfig();

    /*Check that the db client implementation is properly parsed.*/
    BOOST_CHECK(DB_AAAA == dbClientConfig.getImpl());
    /*Check that the db client  host is properly parsed.*/
    BOOST_CHECK(strcmp("127.0.0.1", dbClientConfig.getHost().c_str()) == 0);
    /*Check that the db client port is properly parsed.*/
    BOOST_CHECK(3000 == dbClientConfig.getPort());
    /*Check that the db client namespace is properly parsed.*/
    BOOST_CHECK(strcmp("test", dbClientConfig.getNamespace().c_str()) == 0);
    /*Check that the db client set is properly parsed.*/
    BOOST_CHECK(strcmp("test-set", dbClientConfig.getSet().c_str()) == 0);

    BOOST_TEST_MESSAGE("test_db_client_config_check_valid_json_str end");
}
BOOST_AUTO_TEST_SUITE_END()

我收到以下錯誤:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

我搜索了一下,發現人們建議添加一個主要功能來解決此問題。 但是在添加了main函數之后,即使沒有出現錯誤,但是創建的目標文件說configuration_test.o也不執行任何操作。 它不執行任何測試用例。

有人可以幫我解決這個問題嗎?

BOOST_TEST_DYN_LINKBOOST_TEST_MODULE是影響<boost/test/unit_test.hpp>行為的選項宏。 必須包含標頭之前定義它們,否則其中的代碼將無法使用它們。

移動

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE XXX_Service

到頂部,之前

#include <boost/test/unit_test.hpp>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM