CeresConfig.cmake Eigen dependency

1,271 views
Skip to first unread message

Aditya Gadre

unread,
Apr 4, 2015, 10:00:06 PM4/4/15
to ceres-...@googlegroups.com
I am using Ceres on Mac OS X Yosemite. Ceres was installed using MacPorts. Version of Ceres is 1.10.0 and that of Eigen is 3.2.4. The documentation on ceres-solver.org mentions that version of Eigen should be 3.2.1 or higher. The CeresConfig.cmake file however insists on exact Eigen version of 3.2.2. For me, this results in failure of "find_package(Ceres)". I think the following line in CeresConfig.cmake

FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} EXACT QUIET)

should be changed to

FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} QUIET)

Since CERES_EIGEN_VERSION is set to 3.2.2, it will ensure minimum version requirement, but remove the exact match as it is too restrictive.

I would greatly appreciate any input, and may be a better solution that what I have mentioned above.

Thanks!

Aditya Gadre

unread,
Apr 5, 2015, 1:02:26 PM4/5/15
to ceres-...@googlegroups.com
I looked at the ceres-solver source and the cmake/CeresConfig.cmake.in file gets Eigen version during build time. So I think it may be a reasonable idea to change the line

FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} EXACT QUIET)

to

FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} QUIET)

in cmake/CeresConfig.cmake.in in ceres-solver source. Please let me know if there is another way of circumventing the issue.

Thanks!

Sameer Agarwal

unread,
Apr 6, 2015, 12:33:29 PM4/6/15
to ceres-...@googlegroups.com
Aditya,

We are working on this, and its a bit of a complicated mess that Keir can explain in detail. 

What the documentation says is that any version of eigen later than 3.2.1 will work, but it does not mean you can compile ceres with one version and use another one when building your application that links into ceres.

Relaxing the version matching constraint can lead to some very hard to debug bugs.  You should use the same version of all dependent libraries that you built ceres with, including eigen. 

Sameer



--
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/43dfe964-c5e3-4a68-a988-b152d5b14bbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aditya Gadre

unread,
Apr 6, 2015, 2:44:36 PM4/6/15
to ceres-...@googlegroups.com
Thanks Sameer! I will activate eigen 3.2.2 in macports instead of 3.2.4.
- Aditya

Aditya Gadre

unread,
Apr 7, 2015, 5:08:48 PM4/7/15
to ceres-...@googlegroups.com
I initially made it to work by installing Eigen 3.2.2 in MacPorts. My expectation was that since ports are maintained by MacPorts, ceres-solver would be built against the current version of Eigen. However, it does not appear to be the case. So a better solution, than installing different version of Eigen and potentially of other ceres-solver dependencies, is to build ceres-solver from source in MacPorts. By default MacPorts installs a port from binary archive. I ended up using "sudo port install -s ceres-solver", which built ceres-solver against the current versions of all dependencies. There is a small drawback with this approach though - every time a dependency version changes, it will be necessary to rebuild ceres-solver; until MacPorts maintainer of ceres-solver starts rebuilding it in their tree. I hope this solution may be useful to someone in the same situation as I found myself in.
- Aditya

On Saturday, April 4, 2015 at 10:00:06 PM UTC-4, Aditya Gadre wrote:

Björn Piltz

unread,
Apr 14, 2015, 5:25:38 AM4/14/15
to ceres-...@googlegroups.com
Relaxing the version matching constraint can lead to some very hard to debug bugs
I'm very curious about this. Could you explain in a sentence where the problem arises, since one would assume that, Eigen being entirely inline and you never using Eigen containers to pass data between user and library code, it would be safe.

Björn 

--
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.

Sameer Agarwal

unread,
Apr 14, 2015, 8:13:54 AM4/14/15
to ceres-...@googlegroups.com
We have NormalPrior in the public api which takes Eigen matrices and vector as input and is compiled into the library  :/

Björn Piltz

unread,
Apr 14, 2015, 9:25:46 AM4/14/15
to ceres-...@googlegroups.com

Ok got it. So you just need to inline the NormalPrior ctor and copy the matrices to some internal container. Or just deprecate NormalPrior and add an inline version(to keep the ABI).

Right?

Keir Mierle

unread,
Apr 14, 2015, 11:54:59 PM4/14/15
to ceres-...@googlegroups.com
Hi Björn ,

Without strict checking, there will be violations of the One Definition RuleThe ODR makes transient, internal dependencies hard to deal with, unfortunately, but violating it is the source of real bugs. Here's a Dr. Dobbs article that shows one such case. Unfortunately, when compiling the linker is not always able to enforce the ODR. It happily takes whatever definition is found first on the link command line. With template libraries like Eigen, each translation unit will end up with separate (but identical!) definitions of Eigen functions; so the ODR is not violated. However, if Eigen versions are mixed, than library A can end up with different versions of the same function than library B.

Let me know if this is not clear and I'm happy to expand.

Thanks,
Keir

Keir Mierle

unread,
Apr 15, 2015, 12:08:23 AM4/15/15
to ceres-...@googlegroups.com
I found another article that talks about other sources of ODR violations, in case anyone is curious.

Björn Piltz

unread,
Apr 16, 2015, 4:22:31 AM4/16/15
to ceres-...@googlegroups.com
Hi Keir,
thanks for explaining!
Those two articles both explicitly say "non inlined" functions, though. But I guess one can't be sure all Eigen functions are actually inlined. Two observations: 
* This problem doesn't exist in shared builds on Windows, so the check is unnecessary there (if NormalPrior gets fixed). How about .so files? Is there any way to make sure the Eigen functions are not exported?
* Checking the version isn't really enough since Eigen's ABI changes depending on #defines regarding SSE, AVX, Row vs Col Major, etc.

My concern isn't theoretical. I had the same problem as Aditya with MacPorts. Since Eigen and Ceres are updated independently - more often than not Ceres just won't work out of the box. So it would be nice to find a solution to this problem.

Thanks for all the great work!

Keir Mierle

unread,
Apr 16, 2015, 9:16:31 PM4/16/15
to ceres-...@googlegroups.com, Nick Lewycky
Hi Björn,

Unfortunately inlining doesn't help since you have to control over which parts of Eigen get inlined. That's a good point that the problem may not exist when using dynamic linking. I've CC'd Nick Lewycky, who is a true expert (unlike me) and may have more insight. You're right about the ABI changes due to Eigen config - not sure what the right solution is there.

Keir

HA

unread,
Jul 30, 2015, 11:02:27 AM7/30/15
to Ceres Solver, agad...@gmail.com
Hi,

I believe I am getting a similar problem discussed in this thread. I have installed Eigen 3.2.4 on a Mac via brew. When I run my cmake file it says:

CMake Error at /usr/local/share/Ceres/CeresConfig.cmake:85 (MESSAGE):

Failed to find Ceres - Missing required Ceres dependency: Eigen version

3.2.3, please set EIGEN_INCLUDE_DIR.


From the previous posts in this thread I understand that an earlier version of Eigen should be installed? Is this the case here too?

Alex Stewart

unread,
Jul 30, 2015, 4:49:31 PM7/30/15
to ceres-...@googlegroups.com
You could, but it would be better to keep your current Eigen version and rebuild & reinstall Ceres against the new version of Eigen.  The key point is that the installed version of Eigen and the version of Eigen that Ceres was built with have to match:

brew uninstall ceres-solver
brew install ceres-solver --HEAD

should do it.  Without the --HEAD I expect you would probably get a bottle that has been built against an earlier Eigen version to the one you have installed.

-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.

HA

unread,
Jul 30, 2015, 7:57:02 PM7/30/15
to Ceres Solver, alex...@gmail.com
Awesome! It worked. Thank you.
Reply all
Reply to author
Forward
0 new messages