I am asking about veins the vehicle network simulator.
In my veins application, I want to fetch some data available on a backend server through an API call.
I tried to use curl inside initialize function and I get this error:
/home/veins/workspace.omnetpp/simple_road/simple_road: symbol lookup error: /home/veins/src/veins/src/libveins.so: undefined symbol: _ZN5veins10MyVeinsApp7callAPIENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Simulation terminated with exit code: 127 Working directory: /home/veins/workspace.omnetpp/simple_road Command line: simple_road -m -n .:../../src/veins/examples/veins:../../src/veins/src/veins --image-path=../../src/veins/images -l ../../src/veins/src/veins omnetpp.ini
Environment variables: PATH=/home/veins/src/omnetpp-5.6.2/bin::/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/veins/bin:/home/veins/src/omnetpp/bin:/home/veins/src/sumo/bin:/home/veins/src/veins/bin LD_LIBRARY_PATH=/home/veins/src/omnetpp-5.6.2/lib::/home/veins/src/veins/src: OMNETPP_IMAGE_PATH=/home/veins/src/omnetpp-5.6.2/images
Code snippets:
void MyVeinsApp::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
if (stage == 0) {
// Initializing members and pointers of your application goes here
callAPI("posts/1");
}
else if (stage == 1) {
// Initializing members that require initialized other modules goes here
}
}
size_t writeCallBack(void* contents, size_t size, size_t nmemb, void *userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void callAPI(string path) {
CURL* curl;
CURLcode res;
string buffer;
curl = curl_easy_init();
if(curl) {
const string url = SERVER_URL + path;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallBack);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
EV << "code: " << res << ", data: " << buffer << endl;
}
}