I am able to use the static C++ tensorflow library in a standalone C++ program but not able to use the static library in a qmake project to use that standalone program in other files! I am using the linker options for -Wl,--allow-multiple-definition, -Wl,--whole-archive but to no effect.
I compile my standalone program (test.cpp) using the following command:
g++ -std=c++11 -Wl,--whole-archive -Wl,--allow-multiple-definition \
-Wl,-O1 -Wl,-rpath,'$ORIGIN/lib' -Iinclude -Llib infer.o test.cpp \
-ltensorflow_cc -ltensorflow_framework -o exec
In my qmake project, the target (test with multiple dependencies) is built with:
g++ -m64 -Wl,--allow-multiple-definition -Wl,--whole-archive -Wl,
-O1 -Wl,-rpath,'$ORIGIN/lib' $(OBJECTS)/*.o \
-L../lib/debugL../quackleio/lib/debug -L../lib/release \
-L../quackleio/lib/release -L/usr/lib/86_64-linux-gnu -lquackleio -lquackle \
-L../'$ORIGIN/lib' -ltensorflow_framework -ltensorflow_cc -lQtxGui -lQtCore \
-lpthread -o test
Both these compile successfully without any errors. However, the standalone C++ program runs without any errors while the qmake throws the following errors:
E tensorflow/core/common_runtime/session.cc:69] Not found: No session factory registered for the given session options: {target: "" config: } Registered factories are {}.
F inference/infer.cpp:16] Non-OK-status: NewSession(opts, &session) status: Not found: No session factory registered for the given session options: {target: "" config: } Regisstered factories are {}.
Aborted (core dumped)
On digging somewhat deeper, executing the command ldd on test gives the output (simplied, shown only relevant libraries):
ldd ./test
linux-vdso.so.1 => (0x00007ffda65de000)
libtensorflow_framework.so => /home/rishabh/quackle/inference/lib/libtensorflow_framework.so (0x00007f85d34fb000)
While on running the same command on the executable of the standalone C++ program (exec), I get the output(again showing only relevant libraries):
ldd ./exec
linux-vdso.so.1 => (0x00007ffd8e09e000)
libtensorflow_cc.so => /home/rishabh/quackle/rishabh_code/inference/./lib/libtensorflow_cc.so (0x00007f8e45873000)
libtensorflow_framework.so => /home/rishabh/quackle/rishabh_code/inference/./lib/libtensorflow_framework.so (0x00007f8e44cbb000)
From those outputs, it can be observed the libtensorflow_cc.so is not shown as a dependency of the test executable while it is a dependency of the exec file. However, both of them uses the same class infer.h as their dependency.
The code of the file infer.h is as follows:
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/graph/default_device.h"
#include "tensorflow/core/platform/env.h"
using namespace tensorflow;
class NNInference
{
private:
std::string graph_definition;
Session* session;
std::vector<Tensor> outputs;
Tensor input_tensor;
public:
NNInference(const string &, int);
~NNInference();
float getOutput(std::vector<float> &);
};
Can someone please help me regarding what could be the problem here? How to use the libtensorflow_cc.so in a qmake project successfully? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire