Skip to content

Shared-library integration: configuration mismatch is difficult to diagnose #2139

Description

@randomMesh

When using Jolt as a shared library, it is quite difficult to determine the required preprocessor definitions for the consuming application.

I built Jolt as a shared library with:

JPH_BUILD_SHARED_LIBS=ON
CMAKE_BUILD_TYPE=Release

The generated Jolt library had these relevant defines:

JPH_SHARED_LIBRARY
JPH_DEBUG_RENDERER
JPH_OBJECT_LAYER_BITS=16
JPH_OBJECT_STREAM
JPH_PROFILE_ENABLED
JPH_USE_CPU_COMPUTE

My application initially compiled and linked against libJolt.so, but at runtime RegisterTypesInternal() aborted because the application's Jolt configuration did not match the library configuration.

Adding JPH_PROFILE_ENABLED to the application then resulted in:

undefined reference to JPH::ProfileThread::sInstance'`

The reason for that error was that the application also needed:

JPH_SHARED_LIBRARY

With both definitions present, everything worked:

JPH_SHARED_LIBRARY
JPH_PROFILE_ENABLED
JPH_DEBUG_RENDERER
JPH_OBJECT_LAYER_BITS=16
JPH_OBJECT_STREAM
JPH_USE_CPU_COMPUTE

The problem is that the intermediate errors don't make the required configuration particularly apparent. In particular:

  • RegisterTypesInternal() eventually calls abort(), without clearly identifying which configuration differs.
  • JPH_PROFILE_ENABLED alone produces a linker error because JPH_SHARED_LIBRARY is also required.
  • The need for JPH_SHARED_LIBRARY when consuming the shared library isn't obvious from the linker error.
  • The required application-side definitions have to be manually inferred from the Jolt build configuration.

Would it be possible to improve the documentation and/or diagnostics around shared-library integration?

For example, RegisterTypesInternal() could report the specific configuration flags that differ between the application and the library instead of simply aborting. The build documentation could also provide an explicit example of the preprocessor definitions required when consuming a CMake-built shared Jolt library.

This may be especially useful for users integrating Jolt into IDE-managed projects rather than consuming it directly through CMake's exported Jolt target.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions