我在我的項目未定義的參考`json11 :: Json的::轉儲(的std :: string&)常量」 collect2:錯誤:LD返回
#include "crow_all.h"
#include "sqlOperations/sqlcpp_db_connection.cpp"
#include "date.h"
#include <json11.hpp>
int main() {
crow::SimpleApp app;
CROW_ROUTE(app,"/navOfFund")
.methods("POST"_method)
([](const crow::request& req){
auto x = crow::json::load(req.body);
if (!x)
return crow::response(400);
auto name = x["fund_name"].s();
std::ostringstream os;
vector<double>nav = select_from_fund_type(name);
json11::Json json(nav);
//std::cout << json.dump() << std::endl;
return crow::response{json.dump()};
});
crow::logger::setLogLevel(crow::LogLevel::Debug);
app.port(18080).multithreaded().run();
return 0;
}
使用json11 1個退出狀態,我編譯我的項目使用以下命令
g++ -std=c++1y -L/usr/local/lib -I ../../date main.cpp -ljson11 -lsqlpp-mysql -lmysqlclient -lboost_system -lpthread
和錯誤是
/tmp/ccqQDgWQ.o: In function `json11::Json::dump() const':
main.cpp:(.text._ZNK6json114Json4dumpEv[_ZNK6json114Json4dumpEv]+0x2c): undefined reference to `json11::Json::dump(std::string&) const'
collect2: error: ld returned 1 exit status
我無法找到錯誤的根源。
但我不知道爲什麼,這工作得很好。
#include <iostream>
#include <json11.hpp>
int main()
{
std::vector<double> test_vector { 0.1, 0.2, 0.3, 0.4, 0.5 };
json11::Json json(test_vector);
std::cout << json.dump() << std::endl;
}
而且使用
g++ -std=c++1y json_test.cpp -ljson11
嘗試'json11.cpp',而不是在命令行'-ljson11'。可能是圖書館是用不兼容的標誌建造的。 –
@MaximEgorushkin:同樣的結果:( – Shravan40