facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.94k forks source link

Difficulties Building on Windows #666

Open J-norton opened 7 years ago

J-norton commented 7 years ago

I'm using Windows 10 to build and have been trying to build Caffe 2 using Visual Studio 14 2015 for a while with no luck. I've built protoc, using the directions described in the installation and pointed CMake to the location for that executable.

At that point I used the CMake GUI to configure the solution generation and I generated the solutions. I I end up with a solution with 16 projects (I disabled a lot of optional items). When I try to build the solution, I get an error that an #include directive can't be resolved.

C:\Users\James\Source\Repos\caffe2\caffe2/operators/funhash_op.h(4): fatal error C1083: Cannot open include file: 'xxhash.h': No such file or directory

My guess is that something in the CMake configuration is wrong, but I'm not sure what. I am attaching the CMakeCache.txt file that is generated. It's worth noting that the error that I see is within the Caffe2_CPU project. I have an Nvidia GPU and CUDA 8.0 installed, so if there is a way to disable the CPU project from the build that would be great.

Any help is much appreciated.

CMakeCache.txt

visual studio error capture

J-norton commented 7 years ago

Has anyone else encountered this issue before? I merged the latest and spent a while trying to configure different CMake options, but I am consistently seeing this error that xxhash.h is not found regardless of what I try.

Anybody built this on Windows before willing to share their experience?

Yangqing commented 7 years ago

This seems to happen because of funhash.h - it is currently being moved to experiments/ and is not being compiled in default, could you pull the latest repository and retry?

cgpoh commented 7 years ago

@J-norton Below are the steps that I follow to build successfully on Windows

find_path(Snappy_INCLUDE_DIR NAMES snappy.h PATHS $ENV{SNAPPY_ROOT_DIR} $ENV{SNAPPY_ROOT_DIR}/include)

find_library(Snappy_LIBRARIES NAMES snappy64 PATHS $ENV{SNAPPY_ROOT_DIR} $ENV{SNAPPY_ROOT_DIR}/lib)

include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Snappy DEFAULT_MSG Snappy_INCLUDE_DIR Snappy_LIBRARIES)

if(SNAPPY_FOUND) message(STATUS "Found Snappy (include: ${Snappy_INCLUDE_DIR}, library: ${Snappy_LIBRARIES})") mark_as_advanced(Snappy_INCLUDE_DIR Snappy_LIBRARIES) caffe_parse_header(${Snappy_INCLUDE_DIR}/snappy-stubs-public.h SNAPPY_VERION_LINES SNAPPY_MAJOR SNAPPY_MINOR SNAPPY_PATCHLEVEL) set(Snappy_VERSION "${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}") endif()

and FindGFlags.cmake modification:

- Try to find GFLAGS

#

The following variables are optionally searched for defaults

GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found

#

The following are set after configuration is done:

GFLAGS_FOUND

GFLAGS_INCLUDE_DIRS

GFLAGS_LIBRARIES

GFLAGS_LIBRARYRARY_DIRS

include(FindPackageHandleStandardArgs)

set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")

We are testing only a couple of files in the include directories

if(WIN32) find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS $ENV{GFLAGS_ROOT_DIR}) else() find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS $ENV{GFLAGS_ROOT_DIR}) endif()

if(MSVC) find_library(GFLAGS_LIBRARY_RELEASE NAMES gflags PATHS $ENV{GFLAGS_ROOT_DIR} PATH_SUFFIXES Lib)

find_library(GFLAGS_LIBRARY_DEBUG
    NAMES gflagsd
    PATHS $ENV{GFLAGS_ROOT_DIR}
    PATH_SUFFIXES Lib)

set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})

else() find_library(GFLAGS_LIBRARY gflags) endif()

find_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)

if(GFLAGS_FOUND) set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR}) set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY}) message(STATUS "Found gflags (include: ${GFLAGS_INCLUDE_DIR}, library: ${GFLAGS_LIBRARY})") mark_as_advanced(GFLAGS_LIBRARY_DEBUG GFLAGS_LIBRARY_RELEASE GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR GFLAGS_ROOT_DIR) endif()


- Run `build_windows.bat` and once it build successfully, remember to set `PYTHONPATH` to your caffe2 build directory in the Windows environment variable.

I hope it helps :)
J-norton commented 7 years ago

Oh cool thanks for sharing! I had given up hope and was happily coding with Caffe 1 XD.

I just pulled the latest and I'll try to rebuild, if that doesn't work I'll try your suggestions @cgpoh and see if that fixes it.

Update:

Okay so pulling the latest changes did not work (I got like 3000 link errors), @cgpoh I'm following your guide now, thanks for the detailed instructions. I'm hunting down the build dependencies. Mine are slightly different from yours, but your script modification for gflags worked for me.

I'm a bit confused by your advice for LevelDB. I see the following error in CMake GUI:

CMake Warning at cmake/Dependencies.cmake:126 (message): Not compiling with LevelDB. Suppress this warning with -DUSE_LEVELDB=OFF Call Stack (most recent call first): CMakeLists.txt:72 (include)

It looks like CMake expects to find LevelDB, but you mention rebuilding it in Visual Studio, do I need to generate the project, build it, and then set the paths? Would you mind attaching the CMakeCache.txt file that you have so that I can compare it against my own?

Also in general, I'm a bit confused as to why I need to satisfy the dependencies in the first place to build the core Caffe 2. The CMake scripts seem to think that building without the 3rd party libraries is possible (glog, gflags, etc.)

cgpoh commented 7 years ago

Hi @J-norton, I'm attaching my CMakeCache.txt CMakeCache.txt

After my successful build in Windows, I'm facing a problem with make_mnist_db.exe. I didn't managed to generate db with this exe. Is it possible to let me know if you are facing this problem too?

J-norton commented 7 years ago

Hey thanks for sharing. Yeah I'll keep you posted when I take a look. I'm currently using Caffe 1 for work but we're considering upgrading, anyways I haven't had a ton of time to invest in Caffe 2 but I'm going to take a look tonight.

Are you talking about the digit recognition example network? I think I encountered the same problem when using Caffe 1, if that's the problem you're talking about.

Isaamarod commented 6 years ago

@cgpoh I have the same problem with make_mnist_db.exe