按照官网的步骤一步步弄下来,发现错误一大堆——这就是菜鸟的郁闷……
在google网上看到这篇文章,copy 过来,备用。
源网页地址:http://www.grandmaster.nu/blog/?page_id=628
内容看下面,这里说一下文章作者用的是VSt012,我用VS2010也成功了。(好开心……用CMake第一次成功的,漫漫学习路……)其中CXSparse库不是必需的,官网也提到了除了eigen, gflags and glog, 其它依赖库都是可选的。我认为最重要的是后面那个去掉BUILD_TESTING的步骤和设置Preprocessor Definitions的,虽然现在还不知道是为什么,但还是照做了,与官网步骤不同的也就这两点吧……
谁能告诉我,这是为什么呢?
A while back Google released their nonlinear least-squares minimizer, Ceres, to the public as open source. The tech is really good and very difficult to build by yourself, so I really applaud them for doing so.
Regrettably, it has been an incredible pain to get it to work under Windows. Mostly the glog dependency just didn’t play nice with my compiler.
In the end I got it to work with Visual Studio 2012 Express, and these are the exact steps I did to get there. This is probably helpful for those who are having trouble.
Downloads
1. Get the Ceres Solver source code (tar.gz) from http://code.google.com/p/ceres-solver (v1.4.0 at time of writing)
2. Get the Google Commandline Flags source code from http://code.google.com/p/gflags (v2.0 at time of writing)
3. Get the Google Logger source code from http://code.google.com/p/google-glog (v0.3.2 at time of writing)
4. Get a forked version from CXSparse from https://github.com/PetterS/CXSparse (v3.1.1 at time of writing)
5. Get the Eigen3 library from http://eigen.tuxfamily.org (v3.1.2 at time of writing)
6. Get CMake from http://www.cmake.org/ (v2.8.10 at time of writing)
Installation
1. Install CMake (if you haven’t already)
Folder structure
1. Create a base folder ‘ceres’
2. Extract the Ceres Solver source to its own subfolder ‘ceres/ceres-solver’
3. Extract the gflags source to its own subfolder ‘ceres/gflags’
4. Extract the glog source to its own subfolder ‘ceres/glog’
5. Extract the CXSparse source to its own subfolder ‘ceres/cxsparse’
6. Extract the Eigen source to its own subfolder ‘ceres/eigen’
gflags
1. Open the solution ‘ceres/gflags/gflags.sln’
2. Auto-migrate the solution to MSVC2012, enable one-way upgrades for all projects
3. Toggle ‘release’ mode compilation
4. Compile the project (expect 49 warnings, 0 errors)
glog
1. Open the solution ‘ceres/glog/google-glog.sln’
2. Auto-migrate the solution to MSVC2012, enable one-way upgrades for all projects
3. Open the ‘port.h’ file and comment line that says ‘#define hash hash_compare’ (line 97); or wrap it in a #if (_MSC_VER < 1700)
4. Open the 'logging.cc' file and replace the line '_asm int 3' (line 1262) with '__debugbreak();' (for 64 bit compilation compatibiltiy)
5. Toggle 'release' mode compilation
6. Compile the project (expect 5 warnings)
CXSparse
1. Open the solution ‘ceres/cxsparse/Project/CXSparse/CXSparse.sln’
2. Update compiler and libraries
3. Toggle ‘release’ mode compilation
4. Compile the project (expect 6 warnings)
At this point we’re ready to start creating the solution for Ceres Solver… start CMake-Gui. In this part, make sure to use the complete, absolute paths to all includes and libraries.
CMake
1. Set ‘Where is the source code’ to the ‘ceres/ceres-solver’ folder
2. Set ‘Where to build the binaries’ to ‘ceres/build’
3. Click ‘configure’, ‘create new directory’ and specify ‘Visual Studio 11′ as the generator for this project
4. Set the ‘CXSPARSE_INCLUDE’ value to earlier extracted ‘ceres/cxsparse/Include’
5. Set the ‘CXSPARSE_LIB’ value to the earlier compiled ‘ceres/cxsparse/Lib/CXSparse.lib’
6. Set the ‘GFLAGS_LIB’ value to the earlier compiled ‘ceres/gflags/Release/libgflags.lib’
7. Click ‘configure’
8. Set the ‘GFLAGS_INCLUDE’ value to the earlier extracted ‘ceres/gflags/src/windows’
9. Click ‘configure’
10. Set the ‘GLOG_LIB’ value to the earlier compiled ‘ceres/glog/Release/libglog.lib’
11. Click ‘configure’
12. Set the ‘GLOG_INCLUDE’ value to the earlier extracted ‘ceres/glog/src/windows’
13. Click ‘configure’
14. Set the ‘EIGEN_INCLUDE’ value to the earlier extracted ‘ceres/eigen’
15. Uncheck the ‘BUILD_TESTING’ setting (tests just give lots of compilation errors at this point)
16. Click ‘configure’
17. Click ‘generate’
Now we are ready to compile Ceres Solver.
1. Open ‘ceres/build/CERES.sln’
2. Right click on the ‘ceres’ project and go to the project properties
3. Toggle ‘All Configurations’
4. In the ‘C/C++ / Preprocessor / Preprocessor Definitions’ add ‘GLOG_NO_ABBREVIATED_SEVERITIES’
5. Compile the project
6. Copy ‘ceres/gflags/Release/libgflags.dll’ to ‘ceres/build/bin/Release’
7. Copy ‘ceres/glog/Release/libglog.dll’ to ‘ceres/build/bin/Release’
8. Run Powell.exe to test the library
Aaand it’s working! Using the library in your own projects is a matter of adding the include folders ‘ceres/ceres-solver/include’, ‘ceres/glog/src/windows’, ‘ceres/gflags/src/windows’ and ‘ceres/eigen’, linking to ‘ceres/build/lib/release/ceres.lib’ and adding the ‘libglog.dll’ and ‘libgflags.dll’ binaries.
Of course creating debug or 64 bit versions involves doing everything once more, with the relevant compilation flags active at each stage.
Hope this helps!