我在我的项目未定义的参考`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