0

I am trying to get tensor flow working and so far I have this:

I installed TF from https://www.tensorflow.org/install/lang_c

I am running on Windows 10 and have copied and pasted the contents of the TF lib and include folders to their respective folders in MinGW. I then copied and pasted the example code from the website under a file named 'hello_tf.c' in VS Code. Any time I try to build it, or run it from the command line using "gcc hello_tf.c -ltensorflow -o hello_tf" it results in this error:

6: undefined reference to `_imp__TF_Version'
collect2.exe: error: ld returned 1 exit status

I cannot seem to find an answer that applies to both my situation and my operating system.

Code:

#include <stdio.h>
#include <tensorflow/c/c_api.h>

int main() {
  printf("Hello from TensorFlow C library version %s\n", TF_Version());
  return 0;
}
  • When you see the _imp__ you are missing linking to an import library that goes with a dll. You may have msvc binaries and need MinGW. – drescherjm Apr 19 '22 at 00:28
  • I have MinGW installed but just to make sure I have everything needed where would I find these MinGW binaries? – codingMakesMeCry Apr 19 '22 at 00:35
  • I meant you may need dlls compiled specifically for MinGW. With c++ based libraries usually they are not compatible between different compilers. – drescherjm Apr 19 '22 at 01:13
  • From what I have found so far, those that attempt to use TensorFlow and are using MinGW don't get shut down by other users saying that MinGW isn't compatible. I also have not found anything saying it won't work. – codingMakesMeCry Apr 19 '22 at 01:26

1 Answers1

-1

Add the tensor flow import lib to your gcc command line:

gcc hello_tf.c -o hello_tf tensorflow.lib

See this page for more information on linking dlls on Windows: Link against a Windows .dll+.lib file combination with GCC under Cygwin?

Bill Morgan
  • 538
  • 2
  • 14
  • that returns ```gcc: error: tensorflow.dll: No such file or directory``` When I use the full file path it returns the original error. I'm looking at the link you provided but I'm still very confused. – codingMakesMeCry Apr 19 '22 at 01:13
  • 1
    hmm... maybe try putting both the .lib and .dll in the same directory as the C source code and run gcc from that path. I'm not on a Windows machine at the moment or I'd try it. – Bill Morgan Apr 19 '22 at 01:25
  • I can't seem to find the C source code. – codingMakesMeCry Apr 19 '22 at 01:46
  • The C source code I mean is the .c file with the int main() function in it that you posted in the question. So that dir would have your main.c, tensorflow.lib and tensorflow.dll all in the same dir. Copy the lib and dll there. – Bill Morgan Apr 19 '22 at 01:53
  • That did nothing – codingMakesMeCry Apr 19 '22 at 03:33