Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some examples do not work when building g2o to static libraries #58

Open
txq1986 opened this issue Jan 23, 2015 · 6 comments
Open

Some examples do not work when building g2o to static libraries #58

txq1986 opened this issue Jan 23, 2015 · 6 comments
Labels

Comments

@txq1986
Copy link

txq1986 commented Jan 23, 2015

Hi Rainer,

Thank you for the great g2o work and I am trying to use it.

Are you aware of that some examples do not work when building g2o to static libraries (.a files). For example, I got a bunch of errors of tutorial_slam2d
fatal error in creating cache of type TUTORIAL_CACHE_SE2_OFFSET
addEdge: FATAL, cannot resolve caches for edge 0x23416e0
g2o::Cache* g2o::CacheContainer::createCache(const g2o::Cache::CacheKey&)
fatal error in creating cache of type TUTORIAL_CACHE_SE2_OFFSET
addEdge: FATAL, cannot resolve caches for edge 0x23419a0
...

cmake commands: $cmake -DBUILD_SHARED_LIBS=OFF ../
OS: Ubuntu 14.04

Build to shared libraries are completely perfect and all the examples work well. Do you have an idea what is the possible reasons for it? Thanks

XQ

@jsgaobiao
Copy link

I met the same problem.
Have you solved it ? @txq1986

@AlwaysLearningJary
Copy link

I have the same problem, I was thinking the different version of g2o wasn't compatible. But I remove all files, and reinstall g2o again, it still doesn't work well.
OS:Ubuntu 14.04

@jlblancoc
Copy link
Contributor

jlblancoc commented Mar 23, 2017

A classic problem with static linking... compiler optimizes out what it thinks is not used, which is a problem with class factories.

The origin of the problem is this:

    Factory* f = Factory::instance();
    HyperGraph::HyperGraphElement* e = f->construct(key.type());

The factory returns nullptr for string "TUTORIAL_CACHE_SE2_OFFSET", which means that this line is not being executed:

  G2O_REGISTER_TYPE(TUTORIAL_CACHE_SE2_OFFSET, CacheSE2Offset);

The trick used in G2O_REGISTER_TYPE() to ensure the automatic registration is not working with static linking.

I know of this problem because I had to switch to a more complex auto-registration macro for a project of mine.
Solutions:

  • Forget about static linking...
  • Implement something like MRPT_INITIALIZER() in G2O... Basically, to use __attribute__((constructor)); in GCC/CLANG and continue relying on the existing approach for MSVC (so it will not work with static linking, that's a limitation we have!)

Cheers!

@taiping-z
Copy link

@jlblancoc

Hi, I am sorry. I do not understand how to implement something like MRPT_INITIALIZER() in G2O.
Do you have any demos for solving this problem?

Thank you!

@kyosho81
Copy link

do like this
namespace g2o {
namespace tutorial {

	G2O_REGISTER_TYPE_GROUP(tutorial_slam2d);

	G2O_REGISTER_TYPE(TUTORIAL_VERTEX_SE2, VertexSE2);
	G2O_REGISTER_TYPE(TUTORIAL_VERTEX_POINT_XY, VertexPointXY);

	G2O_REGISTER_TYPE(TUTORIAL_PARAMS_SE2_OFFSET, ParameterSE2Offset);

	G2O_REGISTER_TYPE(TUTORIAL_CACHE_SE2_OFFSET, CacheSE2Offset);

	G2O_REGISTER_TYPE(TUTORIAL_EDGE_SE2, EdgeSE2);
	G2O_REGISTER_TYPE(TUTORIAL_EDGE_SE2_POINT_XY, EdgeSE2PointXY);
}

} // end namespace
int main()
{
return 0;
}

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants