C++版tensorflow2.4.0形成,通常有两种方式:

方法一:通过bazel自己编译TensorFlow2.4.0源码

方法二:直接下载已编译好的动态库

本文采用直接下载已编译成功的动态库,下载链接

https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.4.0.zip

 压缩包内包含include头文件以及lib动态库

经测试运行正常

 

测试程序如下:

#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
int main()
{
    /*
    动态调用 不需要lib文件
    */
    // 运行时加载DLL库
    //TensorFlow库为64位dll库
    HMODULE module = LoadLibrary(L"tf_lib\\tensorflow.dll");
    if (module == NULL)
    {
        cout << "动态加载dll失败!" << endl;
        return 1;
    }
    typedef char*(*TF_VersionFunc)(); // 定义函数指针类型
    TF_VersionFunc TF_Version;
    // 导出函数地址
    TF_Version = (TF_VersionFunc)GetProcAddress(module, "TF_Version");
    if (TF_Version == NULL)
    {
        cout << "动态加载函数失败!" << endl;
        return 2;
    }
    cout << "调用的TensorFlow动态库版本为:" << TF_Version() << endl;

    getchar();
    return 0;
}
 

更多推荐