我的編譯我用下面的命令代碼:連接錯誤使用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
我搜索並發現人們建議增加一個主要功能來解決這個問題。但是,添加主函數後,即使錯誤沒有顯示,但創建的對象文件說配置測試.o什麼都不執行。它不執行任何測試用例。
有人可以幫我解決這個問題。
根據一些測試框架編寫測試用例也說明如何正確編譯。您最好參考Boost.Test文檔頁面上的說明。 – Ethouris
感謝Ethouris的迴應。但是相同的代碼在Ubuntu 12.04上正常工作。我只在ubuntu上遇到這個問題14.04 –