Repository: pytorch/pytorch

Issue:
Build Error lib.obj not found
Dear community,

i encountered a build error i can not resolve.  I'm trying to build pytorch with the specs below. The error i'm encountering is this one:

![img](https://s1.imagebanana.com/file/180614/bqRUhDP0.PNG)

## Issue description

Obviously it's lacking a dubious lib.obj for linking. The question is why it is searching for it in the standard Nvidea folder. Shouldn't the files compiled not be safed somewhere else. Furthermore there is no other error before this one in the build process. 

Can anyone help me with what has gone wrong here. I followed the instructions of the regular link:
[pytorch from source](https://github.com/pytorch/pytorch#from-source)

Best regards

## System Info

- PyTorch 
- How you installed PyTorch (conda, pip, source): Source
- Build command you used (if compiling from source): python setup.py install
- OS: Windows 10
- PyTorch version: 0.4
- Python version: 3.6
- CUDA/cuDNN version: 9.0
- GPU models and configuration: GTX 1070
- Visual Studio 17 (15.7.3)
- CMake version: 3.11.1




Discussion:
cc @peterjc123 do you know what's up here?
@Vedaevolution Could you please send me the complete log?
@peterjc123  Sure i can. [Get it here](https://drive.google.com/open?id=1A5_l4TVpiVNlkdrjKh2yQxMfpeNV21ir)
@Vedaevolution And your `CMake` log files, please?
It seems the FindCUDNN is bringing some wrong flags in the linking phase of `caffe2`. 
Sorry for the inconvenience, those should be the ones:

- [Error Log](https://drive.google.com/open?id=1ZkCmHDhtKe-nAVQEo-ChAMZUvThVWUQN)
- [Output Log](https://drive.google.com/open?id=12ZOdl-3sne6adDxyG7vpZdsbnec3crPv)

And what do i need to change?
It seems the `caffe2::cudnn IMPORTED_LOCATION` is not properly set by the `find_library` in `cmake\Modules\FindCuDNN.cmake` L33-39? @Vedaevolution, did you manually set the environmental variable `CUDNN_LIBRARY`? If not, then it's something wrong with the CMake script there.

Resolving patch:
diff --git a/tools/setup_helpers/cudnn.py b/tools/setup_helpers/cudnn.py
--- a/tools/setup_helpers/cudnn.py
+++ b/tools/setup_helpers/cudnn.py
@@ -1,7 +1,7 @@
 import os
 import glob
 
-from .env import IS_WINDOWS, IS_CONDA, CONDA_DIR, check_negative_env_flag, gather_paths
+from .env import IS_WINDOWS, IS_CONDA, CONDA_DIR, check_negative_env_flag, gather_paths, lib_paths_from_base
 from .cuda import USE_CUDA, CUDA_HOME
 
 
@@ -13,10 +13,8 @@
 
 if USE_CUDA and not check_negative_env_flag('USE_CUDNN'):
     lib_paths = list(filter(bool, [
-        os.getenv('CUDNN_LIB_DIR'),
-        os.path.join(CUDA_HOME, 'lib/x64'),
-        os.path.join(CUDA_HOME, 'lib'),
-        os.path.join(CUDA_HOME, 'lib64'),
+        os.getenv('CUDNN_LIB_DIR')
+    ] + lib_paths_from_base(CUDA_HOME) + [
         '/usr/lib/x86_64-linux-gnu/',
         '/usr/lib/powerpc64le-linux-gnu/',
         '/usr/lib/aarch64-linux-gnu/',
@@ -34,6 +32,7 @@
         'C_INCLUDE_PATH',
         'CPLUS_INCLUDE_PATH',
     ])))
+    # Add CUDA related dirs to candidate list
     if IS_CONDA:
         lib_paths.append(os.path.join(CONDA_DIR, 'lib'))
         include_paths.append(os.path.join(CONDA_DIR, 'include'))
@@ -55,6 +54,13 @@
 
     if CUDNN_INCLUDE_VERSION is None:
         pass
+
+    # Check for standalone cuDNN libraries
+    if CUDNN_INCLUDE_DIR is not None:
+        cudnn_path = os.path.join(os.path.dirname(CUDNN_INCLUDE_DIR))
+        cudnn_lib_paths = lib_paths_from_base(cudnn_path)
+        lib_paths.extend(cudnn_lib_paths)
+
     for path in lib_paths:
         if path is None or not os.path.exists(path):
             continue
diff --git a/tools/setup_helpers/env.py b/tools/setup_helpers/env.py
--- a/tools/setup_helpers/env.py
+++ b/tools/setup_helpers/env.py
@@ -22,4 +22,8 @@ def check_negative_env_flag(name, default=''):
 
 
 def gather_paths(env_vars):
-    return list(chain(*(os.getenv(v, '').split(':') for v in env_vars)))
+    return list(chain(*(os.getenv(v, '').split(os.pathsep) for v in env_vars)))
+
+
+def lib_paths_from_base(base_path):
+    return [os.path.join(base_path, s) for s in ['lib/x64', 'lib', 'lib64']]


Test patch: