在将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) {
我查了下,也是冲突问题,至于具体冲突我还在查......