I'm trying to use Pleora SDK for creating a application to load images from a thermal camera. So my first attempt is to find available devices in the network, however I'm facing a weird behavior in C++ that I really have no reasonable explanation: the code flow jumps to somewere else than the main function on the declaration of "PvSystem lSystem" even when it is not being called.
To aid my explanation, here is the code:
#include <iostream>
#include <PvSystem.h>
#include <PvInterface.h>
#include <PvDevice.h>
int DeviceFinding()
{
PvSystem lSystem;
return 0;
}
int main()
{
std::cout << "Application start" << std::endl;
//DeviceFinding();
return 0;
}
This code, when run on Ubuntu 16.04 64bits with the following build line:
g++ weird.cpp -g3 -o WeirdTest -I/opt/pleora/ebus_sdk/Ubuntu-14.04-x86_64/include -L/opt/pleora/ebus_sdk/Ubuntu-14.04-x86_64/lib -lPvBase -lPvBuffer -lPvStream -lPvDevice -lPvGenICam
outputs:
Error: GENICAM_ROOT_V2_4 is not set.
However, if I comment the line with "PvSystem lSystem",
#include <iostream>
#include <PvSystem.h>
#include <PvInterface.h>
#include <PvDevice.h>
int DeviceFinding()
{
// PvSystem lSystem;
return 0;
}
int main()
{
std::cout << "Application start" << std::endl;
//DeviceFinding();
return 0;
}
the application prints what is expected:
Application start
I really have no idea of what is going on. Can someone help me understanding this?
Intializations of global variables are invoked before main starts.
I dont know the Pleora SDK, but a possible explanation of the pattern is that PvSystem references some global object that needs to be constructed (or a global variable initialized through some function) before main starts, the error occurs in that constructor.
When that global object or variable is not referenced anywhere (when you comment the line PvSystem lSystem;) the linker dropped that global object from the linking and no constructor or initializer was called. That is because the linker is allowed to drop unreferenced globals from a library.
On the other hand, when you activate that line, the linker instantiated the global object (or variable) because it is referenced somewhere in PvSystem, and it invoked its constructor (or initializer) before main. That initializer has detected some error in the environment so it exited the application or threw an exception.
Another possibility is, as in @SamVarshavchik 's comment, you have yourself in your code some constructors (for global objects) invoked before main and a bug in those constructors provoked an undefined behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With