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:
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.
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:
The generated Jolt library had these relevant defines:
My application initially compiled and linked against
libJolt.so, but at runtimeRegisterTypesInternal()aborted because the application's Jolt configuration did not match the library configuration.Adding
JPH_PROFILE_ENABLEDto the application then resulted in:undefined reference toJPH::ProfileThread::sInstance'`The reason for that error was that the application also needed:
With both definitions present, everything worked:
The problem is that the intermediate errors don't make the required configuration particularly apparent. In particular:
RegisterTypesInternal()eventually callsabort(), without clearly identifying which configuration differs.JPH_PROFILE_ENABLEDalone produces a linker error becauseJPH_SHARED_LIBRARYis also required.JPH_SHARED_LIBRARYwhen consuming the shared library isn't obvious from the linker error.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
Jolttarget.