{"id":628,"date":"2012-11-25T01:45:15","date_gmt":"2012-11-25T00:45:15","guid":{"rendered":"http:\/\/www.grandmaster.nu\/blog\/?page_id=628"},"modified":"2012-11-28T01:12:26","modified_gmt":"2012-11-28T00:12:26","slug":"google-ceres-solver","status":"publish","type":"page","link":"https:\/\/www.grandmaster.nu\/blog\/?page_id=628","title":{"rendered":"Google Ceres Solver &#8211; Compilation with VC2012"},"content":{"rendered":"<p>A while back Google released their nonlinear least-squares minimizer, <a href=\"http:\/\/code.google.com\/p\/ceres-solver\/\">Ceres<\/a>, 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.<\/p>\n<p>Regrettably, it has been an incredible pain to get it to work under Windows. Mostly the glog dependency just didn&#8217;t play nice with my compiler.<\/p>\n<p>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.<\/p>\n<p><strong>Downloads<\/strong><br \/>\n1. Get the Ceres Solver source code (tar.gz) from <a href=\"http:\/\/code.google.com\/p\/ceres-solver\/downloads\/list\">http:\/\/code.google.com\/p\/ceres-solver<\/a> (v1.4.0 at time of writing)<br \/>\n2. Get the Google Commandline Flags source code from <a href=\"http:\/\/code.google.com\/p\/gflags\/downloads\/list\">http:\/\/code.google.com\/p\/gflags<\/a> (v2.0 at time of writing)<br \/>\n3. Get the Google Logger source code from <a href=\"http:\/\/code.google.com\/p\/google-glog\/downloads\/list\">http:\/\/code.google.com\/p\/google-glog<\/a> (v0.3.2 at time of writing)<br \/>\n4. Get a forked version from CXSparse from <a href=\"https:\/\/github.com\/PetterS\/CXSparse\">https:\/\/github.com\/PetterS\/CXSparse<\/a> (v3.1.1 at time of writing)<br \/>\n5. Get the Eigen3 library from <a href=\"http:\/\/eigen.tuxfamily.org\/index.php?title=Main_Page\">http:\/\/eigen.tuxfamily.org<\/a> (v3.1.2 at time of writing)<br \/>\n6. Get CMake from <a href=\"http:\/\/www.cmake.org\/\">http:\/\/www.cmake.org\/<\/a> (v2.8.10 at time of writing)<\/p>\n<p><strong>Installation<\/strong><br \/>\n1. Install CMake (if you haven&#8217;t already)<\/p>\n<p><strong>Folder structure<\/strong><br \/>\n1. Create a base folder &#8216;ceres&#8217;<br \/>\n2. Extract the Ceres Solver source to its own subfolder &#8216;ceres\/ceres-solver&#8217;<br \/>\n3. Extract the gflags source to its own subfolder &#8216;ceres\/gflags&#8217;<br \/>\n4. Extract the glog source to its own subfolder &#8216;ceres\/glog&#8217;<br \/>\n5. Extract the CXSparse source to its own subfolder &#8216;ceres\/cxsparse&#8217;<br \/>\n6. Extract the Eigen source to its own subfolder &#8216;ceres\/eigen&#8217;<\/p>\n<p><strong>gflags<\/strong><br \/>\n1. Open the solution &#8216;ceres\/gflags\/gflags.sln&#8217;<br \/>\n2. Auto-migrate the solution to MSVC2012, enable one-way upgrades for all projects<br \/>\n3. Toggle &#8216;release&#8217; mode compilation<br \/>\n4. Compile the project (expect 49 warnings, 0 errors)<\/p>\n<p><strong>glog<\/strong><br \/>\n1. Open the solution &#8216;ceres\/glog\/google-glog.sln&#8217;<br \/>\n2. Auto-migrate the solution to MSVC2012, enable one-way upgrades for all projects<br \/>\n3. Open the &#8216;port.h&#8217; file and comment line that says &#8216;#define hash hash_compare&#8217; (line 97); or wrap it in a #if (_MSC_VER < 1700)\n4. Open the 'logging.cc' file and replace the line '_asm int 3' (line 1262) with '__debugbreak();' (for 64 bit compilation compatibiltiy)\n5. Toggle 'release' mode compilation\n6. Compile the project (expect 5 warnings)\n\n<strong>CXSparse<\/strong><br \/>\n1. Open the solution &#8216;ceres\/cxsparse\/Project\/CXSparse\/CXSparse.sln&#8217;<br \/>\n2. Update compiler and libraries<br \/>\n3. Toggle &#8216;release&#8217; mode compilation<br \/>\n4. Compile the project (expect 6 warnings)<\/p>\n<p>At this point we&#8217;re ready to start creating the solution for Ceres Solver&#8230; start CMake-Gui. In this part, make sure to use the complete, absolute paths to all includes and libraries.<br \/>\n<strong>CMake<\/strong><br \/>\n1. Set &#8216;Where is the source code&#8217; to the &#8216;ceres\/ceres-solver&#8217; folder<br \/>\n2. Set &#8216;Where to build the binaries&#8217; to &#8216;ceres\/build&#8217;<br \/>\n3. Click &#8216;configure&#8217;, &#8216;create new directory&#8217; and specify &#8216;Visual Studio 11&#8217; as the generator for this project<br \/>\n4. Set the &#8216;CXSPARSE_INCLUDE&#8217; value to earlier extracted &#8216;ceres\/cxsparse\/Include&#8217;<br \/>\n5. Set the &#8216;CXSPARSE_LIB&#8217; value to the earlier compiled &#8216;ceres\/cxsparse\/Lib\/CXSparse.lib&#8217;<br \/>\n6. Set the &#8216;GFLAGS_LIB&#8217; value to the earlier compiled &#8216;ceres\/gflags\/Release\/libgflags.lib&#8217;<br \/>\n7. Click &#8216;configure&#8217;<br \/>\n8. Set the &#8216;GFLAGS_INCLUDE&#8217; value to the earlier extracted &#8216;ceres\/gflags\/src\/windows&#8217;<br \/>\n9. Click &#8216;configure&#8217;<br \/>\n10. Set the &#8216;GLOG_LIB&#8217; value to the earlier compiled &#8216;ceres\/glog\/Release\/libglog.lib&#8217;<br \/>\n11. Click &#8216;configure&#8217;<br \/>\n12. Set the &#8216;GLOG_INCLUDE&#8217; value to the earlier extracted &#8216;ceres\/glog\/src\/windows&#8217;<br \/>\n13. Click &#8216;configure&#8217;<br \/>\n14. Set the &#8216;EIGEN_INCLUDE&#8217; value to the earlier extracted &#8216;ceres\/eigen&#8217;<br \/>\n15. Uncheck the &#8216;BUILD_TESTING&#8217; setting (tests just give lots of compilation errors at this point)<br \/>\n16. Click &#8216;configure&#8217;<br \/>\n17. Click &#8216;generate&#8217;<\/p>\n<p>Now we are ready to compile Ceres Solver.<br \/>\n1. Open &#8216;ceres\/build\/CERES.sln&#8217;<br \/>\n2. Right click on the &#8216;ceres&#8217; project and go to the project properties<br \/>\n3. Toggle &#8216;All Configurations&#8217;<br \/>\n4. In the &#8216;C\/C++ \/ Preprocessor \/ Preprocessor Definitions&#8217; add &#8216;GLOG_NO_ABBREVIATED_SEVERITIES&#8217;<br \/>\n5. Compile the project<br \/>\n6. Copy &#8216;ceres\/gflags\/Release\/libgflags.dll&#8217; to &#8216;ceres\/build\/bin\/Release&#8217;<br \/>\n7. Copy &#8216;ceres\/glog\/Release\/libglog.dll&#8217; to &#8216;ceres\/build\/bin\/Release&#8217;<br \/>\n8. Run Powell.exe to test the library<\/p>\n<p>Aaand it&#8217;s working! Using the library in your own projects is a matter of adding the include folders &#8216;ceres\/ceres-solver\/include&#8217;, &#8216;ceres\/glog\/src\/windows&#8217;, &#8216;ceres\/gflags\/src\/windows&#8217; and &#8216;ceres\/eigen&#8217;, linking to &#8216;ceres\/build\/lib\/release\/ceres.lib&#8217; and adding the &#8216;libglog.dll&#8217; and &#8216;libgflags.dll&#8217; binaries. <\/p>\n<p>Of course creating debug or 64 bit versions involves doing everything once more, with the relevant compilation flags active at each stage. <\/p>\n<p>Hope this helps!<br \/>\n&#8211; GrandMaster<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. <a class=\"more-link\" href=\"https:\/\/www.grandmaster.nu\/blog\/?page_id=628\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":25,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"ngg_post_thumbnail":0,"footnotes":""},"_links":{"self":[{"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/pages\/628"}],"collection":[{"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=628"}],"version-history":[{"count":9,"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/pages\/628\/revisions"}],"predecessor-version":[{"id":641,"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/pages\/628\/revisions\/641"}],"up":[{"embeddable":true,"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=\/wp\/v2\/pages\/25"}],"wp:attachment":[{"href":"https:\/\/www.grandmaster.nu\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}