Windows compilation problem

1,230 views
Skip to first unread message

arrigo

unread,
Mar 4, 2015, 7:19:51 PM3/4/15
to ceres-...@googlegroups.com
I'm trying to build ceres under Windows using CMake 3.0.1 and Visual Studio 2013. CMake is not able to find gflags:

-- Failed to find gflags - Failed to determine gflags namespace, it is not google or gflags.

Could NOT find Gflags (missing: GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES GFLAGS_NAMESPACE)

-- Did not find Google Flags (gflags), Building without gflags - no tests or tools will be built!


even though GFLAGS_INCLUDE_DIR is set to <omitted>/ceres/gflags-2.1.1/build/include , GFLAG_LIBRARY to <omitted>/ceres/gflags-2.1.1/build/lib/Debug and gflags was built successfully.


Any ideas?


Thanks,


-Arrigo


Sergey Sharybin

unread,
Mar 5, 2015, 1:39:41 AM3/5/15
to ceres-...@googlegroups.com
Hi,

Setting GFLAG_LIBRARY might work, but for that you need to set it to an actual library file, not to a directory with that file. But it's now deprecated i think and proper way is to use  GFLAGS_INCLUDE_DIR_HINTS and GFLAGS_LIBRARY_DIR_HINTS.

Would be something like that in your case:  GFLAGS_INCLUDE_DIR_HINTS=<omitted>/ceres/gflags-2.1.1/build/include GFLAGS_LIBRARY_DIR_HINTS=<omitted>/ceres/gflags-2.1.1/build/lib/Debug


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/c6f38a19-6cf9-4aef-855e-d148e63c76e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
With best regards, Sergey Sharybin

Alex Stewart

unread,
Mar 5, 2015, 4:47:20 AM3/5/15
to ceres-...@googlegroups.com
Arrigo,

I think there are two issues:

1) The prefix is plural: GFLAG —> GFLAGS (however, I think this is just a typo in your email, as it looks like you have got further than you would otherwise have done)

2) This:

GFLAG_LIBRARY to <omitted>/ceres/gflags-2.1.1/build/lib/Debug

Should be the path to the compiled library, i.e: <omitted>/ceres/gflags-2.1.1/build/lib/Debug/libgflags.lib, not just the directory in which the library is contained.

However - Sergey is quite correct that using the HINTS variables is the preferred method to guide the search for dependencies, see here for more info:


You can still set XXX_INCLUDE_DIR & XXX_LIBRARY directly, but you will bypass some of the checks, whereas if you use the HINTS, all checking remains and the error message should have been more informative about failing to find the gflags library.

-Alex

arrigo

unread,
Mar 5, 2015, 5:46:13 PM3/5/15
to ceres-...@googlegroups.com
Thanks a lot for the hints, Alex and Sergey! I am still getting errors from CMake, though. If I set GFLAGS_INCLUDE_DIR to <omitted>/ceres/gflags-2.1.1/build/include and GFLAGS_LIBRARY to <omitted>/ceres/gflags-2.1.1/build/lib/Release/gflags.lib in the CMake GUI, I get


-- Failed to find gflags - Failed to determine gflags namespace, it is not google or gflags.
Could NOT find Gflags (missing:  GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES GFLAGS_NAMESPACE)
-- Did not find Google Flags (gflags), Building without gflags - no tests or tools will be built!

If I set instead GFLAGS_INCLUDE_DIR_HINTS to <omitted>/ceres/gflags-2.1.1/build/include and GFLAGS_LIBRARY_DIR_HINTS to <omitted>/ceres/gflags-2.1.1/build/lib/Release I get

Performing Test GFLAGS_IN_GOOGLE_NAMESPACE
Performing Test GFLAGS_IN_GOOGLE_NAMESPACE - Failed
Performing Test GFLAGS_IN_GFLAGS_NAMESPACE
Performing Test GFLAGS_IN_GFLAGS_NAMESPACE - Failed

-- Failed to find gflags - Failed to determine gflags namespace, it is not google or gflags.
Could NOT find Gflags (missing:  GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES GFLAGS_NAMESPACE)
-- Did not find Google Flags (gflags), Building without gflags - no tests or tools will be built!

By the way, I do not see the GFLAGS_INCLUDE_DIR_HINTS and GFLAGS_LIBRARY_DIR_HINTS variables in the CMake GUI, so I added them with the "Add Entry" button.

-Arrigo

Alex Stewart

unread,
Mar 5, 2015, 6:55:00 PM3/5/15
to ceres-...@googlegroups.com
Arrigo,

Performing Test GFLAGS_IN_GOOGLE_NAMESPACE
Performing Test GFLAGS_IN_GOOGLE_NAMESPACE - Failed
Performing Test GFLAGS_IN_GFLAGS_NAMESPACE
Performing Test GFLAGS_IN_GFLAGS_NAMESPACE - Failed

So both of these checks are performed using check_cxx_source_compiles() in CMake, they are defined in:

<ceres src>/cmake/FindGflags.cmake

at lines 144 & 159 for checking for the ::google & ::gflags namespaces respectively.

As a sanity check, I take it you have no built gflags with a custom namespace, and if you are using the default with 2.1.1 it should be gflags - I take it is on your machine?

I suspect MSVC is complaining about something in the test code so both tests fail, when one of them (the one for ::gflags) should be passing, as the detection logic appears to be working.  What happens if you manually create a test.cpp with the contents of the ::gflags test:

#include <gflags/gflags.h>
int main(int argc, char * argv[]) {
  gflags::ParseCommandLineFlags(&argc, &argv, true);
  return 0;
}

and try to compile it passing: <omitted>/ceres/gflags-2.1.1/build/include as an include directory and <omitted>/ceres/gflags-2.1.1/build/lib/Release/gflags.lib as a link library - what errors does MSVC throw up?

By the way, I do not see the GFLAGS_INCLUDE_DIR_HINTS and GFLAGS_LIBRARY_DIR_HINTS variables in the CMake GUI, so I added them with the "Add Entry" button.

That’s correct - the HINTS variables have to be defined by the user if desired, either via -D when invoking CMake on the command line or via the GUI.

-Alex

arrigo

unread,
Mar 6, 2015, 4:58:25 PM3/6/15
to ceres-...@googlegroups.com
Alex,

in order for MSVC to compile tat small program I had to add Shlwapi.lib to the project, otherwise I would get this error:

1>gflags.lib(gflags.obj) : error LNK2001: unresolved external symbol __imp_PathMatchSpecA
1>C:\Users\arbenede\Documents\projects\BeamSteering\vs\gflags-namespace-test\x64\Release\gflags-namespace-test.exe : fatal error LNK1120: 1 unresolved externals

Maybe the CMake script is missing this information?

-Arrigo

Sylvain Duchêne

unread,
Mar 11, 2015, 11:42:19 AM3/11/15
to ceres-...@googlegroups.com
Hi,
sorry, I was reading the last posts...and I promised in a previous post to share my solution to manage to build Ceres fully under windows...

What s your status ?  Did you manage to compile everything ?

arrigo

unread,
Mar 11, 2015, 1:42:33 PM3/11/15
to ceres-...@googlegroups.com
Sylvain ,

I managed to compile ceres using the Visual Studio solution at https://github.com/tbennun/ceres-windows . There is a minor problem (wrong Include path in the examples project) but other than that I was able to build the libraries. I am still interested in building ceres with CMake from the official Git repository. I'm glad to test your intructions on Visual Studio 2013 if you think that might be useful

Thanks

-Arrigo

Alex Stewart

unread,
Mar 12, 2015, 2:34:33 PM3/12/15
to ceres-...@googlegroups.com
Arrigo,

Could you please try the patch available below, it should hopefully fix the missing Shlwapi issue on Windows when detecting the gflags namespace.  Caveat is that I don’t have a Windows rig to test this on, so YMMV but it closely mirrors the gflags project build requirements, so it should be OK.


-Alex

-- 
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.

Sylvain Duchêne

unread,
Mar 26, 2015, 7:26:28 AM3/26/15
to ceres-...@googlegroups.com
Ok,
so I tried on 2 machines with VS2012 and VS2013 in 64bit, I left a copy there http://sylvain.duchene.im/how-to-build-ceres-under-windows/,
I followed the following procedure, let me know if I forgot somethin, in any case, it started to be easy to build from scratch CERES.
I just included cmake screenshot because the amount of fields to complete is painful...
  1. Download CERES ^^, ceres-solver-1.10.0
  2. Download Eigen , Current Release 3.2.4
  3. Download Glog, glog-0.3.3
    1. Compil will fail: error C2039 std:min not member of std…
    2. => In logging.cc, #include <algorithm>
    3. In logging.cc, replace //_asm int 3 with   __debugbreak();

 

  1. Compilation should be successful in Debug and Release now, (tested with VS2013-VS2012 in X64)

 

  1. Download Gflags, use CMake, it compiles…don’t forget to run install and update Install_prefix_path, such as E:\Dev\LIB\Gflags\gflags-2.1.2\X64Release
  2. Download Suitesparse-metis-for-windows,
    1. Go there https://github.com/jlblancoc/suitesparse-metis-for-windows/releases
    2. Get the latest Release : For me it was v1.2.3, https://github.com/jlblancoc/suitesparse-metis-for-windows/archive/v1.2.3.zip
    3. SET, SUITESPARSE_INSTALL_PREFIX
    4. Configure and build

 




  1. Finally, Use Cmake on Ceres folder
    1. You can have to add missing entry like for GFlags, GFLAGS_NAMESPACE
    2. Fill all field according to the following screenshot, I did not try to configure the project by using the METIS LIBRARY

Alex Stewart

unread,
Mar 26, 2015, 10:32:38 AM3/26/15
to ceres-...@googlegroups.com
Sylvain,

Would it be possible for you to try the master branch of Ceres (available via: git clone https://ceres-solver.googlesource.com/ceres-solver) instead of the 1.10 release?  It should fix this issue:

    1. You can have to add missing entry like for GFlags, GFLAGS_NAMESPACE

on Windows.

Also, for this:

    1. Fill all field according to the following screenshot, 

assuming I understand what you’re saying correctly, you should not have to set each of the fields in the screenshots individually, you should be able to set the HINTS variables (http://ceres-solver.org/building.html#customizing-the-build) when invoking CMake for Ceres and it should detect them for you, which particularly for SuiteSparse should make life much less painful, something like this for your system:

SUITESPARSE_INCLUDE_DIR_HINTS = E:/Dev/LIB/SuiteSparse/bin/include/suitesparse
SUITESPARSE_LIBRARY_DIR_HINTS = E:/Dev/LIB/SuiteSparse/bin/lib64

You can also set the equivalent variables for glog, gflags, CXSparse (and Eigen).

For BLAS & LAPACK, on Windows they should check the LIB environment variable for library locations, you could try setting that to your BLAS install location (this is in addition to the standard CMake vars, such as CMAKE_LIBRARY_PATH, which you could also try setting when invoking CMake for Ceres).

-Alex

-- 
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.

Sylvain Duchêne

unread,
Mar 26, 2015, 7:53:22 PM3/26/15
to ceres-...@googlegroups.com
Hi,
 so I tried with the master branch.
Indeed, It fixes the missing GFLAGS_NAMESPACE issue.

However, with Eigen, BLAS & Lapack, Glog and glags filled  ( to prevent cmake error..)
these macro SUITESPARSE_INCLUDE_DIR_HINTS and SUITESPARSE_LIBRARY_DIR_HINTS only set for me properly all  INCLUDE_DIR .

ps: I have no ENV path set on this machine.

Alex Stewart

unread,
Mar 28, 2015, 12:49:38 PM3/28/15
to ceres-...@googlegroups.com
Sylvain,


(with a clean build directory), I think it should fix you problems, provided that you set the <NAME>_LIBRARY_DIR_HINTS variables for all Ceres dependencies you want to use (glog, gflags, SuiteSparse etc).

-Alex

Sylvain Duchêne

unread,
Mar 30, 2015, 12:11:09 PM3/30/15
to ceres-...@googlegroups.com
Hi,
so I just applied your patch c117b89e.diff and it works :

>  git apply --check c117b89e.diff
>  git am --signoff < c117b89e.diff

However the building failed, but I guess it is for another reason the error is the same for all examples,
MSCVRT.lib(MSVCR120.dll)  conflicted with LIBCMT.lib

So I added  /NODEFAULTLIB:MSVCRT.lib to compile succesfully.

Alex Stewart

unread,
Mar 30, 2015, 12:14:46 PM3/30/15
to ceres-...@googlegroups.com
Sylvain,

Great, I will merge that change into master soon.

Does enabling the MSVC_USE_STATIC_CRT option in the Ceres CMake fix your CRT problem without the /NODEFAULTLIB directive?

-Alex

Sylvain Duchêne

unread,
Mar 30, 2015, 5:08:06 PM3/30/15
to ceres-...@googlegroups.com
Hi,
ok great,
unfortunately enabling the MSVC_USE_STATIC_CR does not fix it ... but building the full pack is very quick now.
Reply all
Reply to author
Forward
0 new messages