0

I am new to C and followed the steps in Tensorflow in C. I am able to compile and run using the below command,

gcc.exe -Iinclude -Llib test.c -ltensorflow -o test.exe

Now I want to try the same in Visual Studio and I am following the steps as in this answer.

I have provided below items in the properties window,

Linker->General->Additional Library Directories as $(SolutionDir)\\lib;
Linker->Input->Additional Dependency as tensorflow.lib;
C/C++->General->Additional Include Directories as $(SolutionDir)\\include;

However I am still getting the link error,

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol __imp__TF_Version referenced in function _main   tf_lstm C:\test\tf\tf_lstm\Source.obj   1   

Can someone support me here?

Selva
  • 951
  • 7
  • 23

1 Answers1

0

There are a few possibilities:

  1. The compiler might not be able to even find tensorflow.lib Double check your linker paths. You've said in your question that the root solution folder contains "tensorflow.lib". Are you sure? Look at the project's Properties >> Linker >> Command Line item. There you can see the full, spelled-out directories that the linker will search. Look at each /LIBPATH: item and be sure that one of them actually contains "tensorflow.lib"

  2. Are you sure that tensorflow.lib is the only link library you need?

  3. A third possibility is that Visual Studio is assuming that the symbol in question is a C++ symbol when it's really a C symbol.

    When C++ compiles/links a function, it decorates the name with all sorts of weird characters indicating aspects that do not exist in C, like calling convention, const-ness of arguments, etc. The characters it uses to decorate the name are things like '@' and others. But the point is, the same function's name becomes different in C++ from what it would be in C, even with the same header-file prototype.

    If you are trying to use functions from a regular "C" DLL within a C++ program, the compiler will assume that they are C++ functions unless it sees extern "C" before the function prototype. The end result is that the function is exported as

    You can put extern "C" individually before each function protottype or in a block around many function prototypes.

Like this:

extern "C" void foo();

or

extern "C"
{
    void foo();
    void bar();
}

You can even have an include file that does this and then includes the tensorflow headers

Joe
  • 5,394
  • 3
  • 23
  • 54