在將tensorflow c++編譯好的動態庫用於QT項目中時遇到了三個問題,現在介紹解決辦法:
1、編譯時報錯:qint32、Qvector等類型沒有定義,找不到定義之類的。
解決:應該是libtensorflow_cc.so與QT衝突,將tensorflow作用域範圍縮小,即不要使用using namespace tensorflow::xxx之類的,用到xxx的地方再加上tensorflow:: 這樣雖然麻煩,但的確解決了這個問題。
2、與libmir(好像是這樣拼寫的,類似這樣的庫,忘了)、libprotobuf版本衝突,會報與此相關的錯。
解決:刪掉/opt/Qt5.9.x/5.9.x/gcc_64/plugins/platformthemes/這個路徑下的庫libgtk3.0,問題解決,但帶來一個小現象,軟件界面字體變小一號,我覺得不影響功能,就沒管。
3、pthread_rwlock_wrlock.c:no such file or directory 好像是libQt5Network.so.5與libtensorflow_framework.so.2導致。
解決:不要使用QNetworkAccessManage->post()這個函數,具體原因我還不知道。反正這個函數是在一個項目未完成的功能裏使用的,這個未完成的功能以後再想辦法實現算了,我把這個函數刪掉了,不影響功能,反正刪掉這句就解決了這個問題。
今天將CNN用於另一個項目,出現:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h: In static member function ‘static void Eigen::internal::TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, BlockRead>::Copy(const Block&, StorageIndex, const Dimensions&, const Dimensions&, const Scalar*, Scalar*)’:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:393:63: error: the value of ‘j’ is not usable in a constant expression
if (++block_iter_state[j].count < block_iter_state[j].size) {
^
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:392:16: note: ‘int j’ is not const
for (int j = 0; j < num_squeezed_dims; ++j) {
^
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:393:35: error: parse error in template argument list
if (++block_iter_state[j].count < block_iter_state[j].size) {
^
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h: In static member function ‘static void Eigen::internal::TensorBlockCwiseUnaryIO<UnaryFunctor, StorageIndex, OutputScalar, NumDims, Layout>::Run(const UnaryFunctor&, const Dimensions&, const Dimensions&, OutputScalar*, Eigen::array<StorageIndex, NumDims>&, const InputScalar*)’:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:604:21: error: parse error in template argument list
if (++state.count < state.size) {
^
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h: In static member function ‘static void Eigen::internal::TensorBlockCwiseBinaryIO<BinaryFunctor, StorageIndex, OutputScalar, NumDims, Layout>::Run(const BinaryFunctor&, const Dimensions&, const Dimensions&, OutputScalar*, Eigen::array<StorageIndex, NumDims>&, const LeftScalar*, Eigen::array<StorageIndex, NumDims>&, const RightScalar*)’:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:758:21: error: parse error in template argument list
if (++state.count < state.size) {
^
In file included from /home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/Tensor:143:0,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/core/framework/tensor.h:21,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/cc/framework/ops.h:21,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/cc/ops/const_op.h:19,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/jinXingCnn.h:25,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/DualEnFitOreStoneRecogProc.h:16,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/XRT_PC_Stream_Mathprocess.h:11,
from ../src/CameraDataProcessThread.h:50,
from ../src/CameraDataProcessThread.cpp:14:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h: In member function ‘void Eigen::TensorEvaluator<const Eigen::TensorReshapingOp<NewDimensions, XprType>, Device>::block(Eigen::TensorEvaluator<const Eigen::TensorReshapingOp<NewDimensions, XprType>, Device>::OutputTensorBlock*) const’:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h:319:35: error: parse error in template argument list
if (++block_iter_state[i].count < block_iter_state[i].size) {
^
In file included from /home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/Tensor:151:0,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/core/framework/tensor.h:21,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/cc/framework/ops.h:21,
from /home/jumper/ThirdPartyLib/tensorflow_cc/include/tensorflow/cc/ops/const_op.h:19,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/jinXingCnn.h:25,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/DualEnFitOreStoneRecogProc.h:16,
from /root/文檔/jinxing/XRT_server_sortingprocessV2.0.2-Release/ExtraDependency/include/XRT_PC_Stream_Mathprocess.h:11,
from ../src/CameraDataProcessThread.h:50,
from ../src/CameraDataProcessThread.cpp:14:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h: In member function ‘void Eigen::TensorEvaluator<const Eigen::TensorGeneratorOp<Generator, XprType>, Device>::block(Eigen::TensorEvaluator<const Eigen::TensorGeneratorOp<Generator, XprType>, Device>::TensorBlock*) const’:
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h:202:28: error: parse error in template argument list
while (it[NumDims - 1].count < it[NumDims - 1].size) {
^
/home/jumper/ThirdPartyLib/tensorflow_cc/include/unsupported/Eigen/CXX11/src/Tensor/TensorGenerator.h:216:21: error: parse error in template argument list
if (++it[i].count < it[i].size) {
我查了下,也是衝突問題,至於具體衝突我還在查......