ValYouW / tflite-dist

TensorFlow Lite C/C++ distribution libraries and headers
MIT License
111 stars 19 forks source link

Windows build unresolved externals #2

Closed OmarJay1 closed 4 years ago

OmarJay1 commented 4 years ago

Hello, thanks for putting this together. I'm finding that that prebuilt packages won't link on Windows. I built my own with the latest TF pull from github, and the .lib will link properly, but there are other problems with that build.

I get these errors: 1>tflite1.obj : error LNK2019: unresolved external symbol "class tflite::ErrorReporter cdecl tflite::DefaultErrorReporter(void)" (?DefaultErrorReporter@tflite@@YAPEAVErrorReporter@1@XZ) referenced in function main 1>tflite1.obj : error LNK2019: unresolved external symbol "public: static class std::unique_ptr<class tflite::FlatBufferModel,struct std::default_delete > cdecl tflite::FlatBufferModel::BuildFromFile(char const ,class tflite::ErrorReporter )" (?BuildFromFile@FlatBufferModel@tflite@@SA?AV?$unique_ptr@VFlatBufferModel@tflite@@U?$default_delete@VFlatBufferModel@tflite@@@std@@@std@@PEBDPEAVErrorReporter@2@@Z) referenced in function main 1>tflite1.obj : error LNK2019: unresolved external symbol "public: __cdecl tflite::FlatBufferModel::~FlatBufferModel(void)" (??1FlatBufferModel@tflite@@QEAA@XZ) referenced in function "public: void __cdecl tflite::FlatBufferModel::`scalar deleting destructor'(unsigned int)" (??_GFlatBufferModel@tflite@@QEAAPEAXI@Z)

#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"

int main(int argc, char* argv[]) 
{
    std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile("mobilenet_v1_1.0_224.tflite");

}

Thanks.

emepetres commented 4 years ago

Hi, you are using the C++ API, but the dll contain only the C API.

In other words, you can only use what it is defined at https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/c. Specially look at c_api.h and common.h files.

OmarJay1 commented 4 years ago

Thanks emepetres. I don't want to be a pest about this, but I don't believe there's a supported C++ API anymore. Only TF Lite & C API as far as I can tell, but I could be wrong.

The only implementation of TF Lite I can get to work on Windows is this:

https://github.com/qintao97/tensorflow_lite

If it suits my needs, I'll probably use it. However, it would be nice to have updates. I'll look into what it takes to make TF Lite work on Windows. The Bazel builds seem to be problematic. The above uses a Visual Studio SLN.

ValYouW commented 4 years ago

I think I had tflite c++ working on windows, or was it c?? I'll check soon and update. Anyway I don't include c++ dll for windows in this distribution as it is huge

OmarJay1 commented 4 years ago

I guess I was talking about a semantic issue. I think there used to be a TF C++ API, but it's no longer there.

The use of .cc files suggests that TF Lite is linked as C++? I'm not sure, but on Windows my calling code is .cpp. I was able to build with the latest Bazel .lib. However, not the .lib in this repository.

The latest Bazel build fails at runtime when I try something like:

const std::vector inputs = interpreter->inputs();

The lib I pointed to works for getting inputs and analyzing graphs. I'm going to try to do some inference soon.

Thanks.

ValYouW commented 4 years ago

As @emepetres said above, the dll/lib in this repo is of the C library, you can't compile your code using tflite c++ headers (eg tensorflow/lite/model.h) and link against the C lib provided here. If you want to use the lib provided here you have to use tflite C headers (i.e tensorflow/lite/c/c_api.h), it does not matter if you write in c++, in this sample I write in C++ but using the C headers of tflite. Do you have to use the c++ headers?