From 85fd37f11dadd32fdbd0bc7fb885e44aaa495a03 Mon Sep 17 00:00:00 2001 From: Francois Kritzinger Date: Wed, 3 Sep 2025 16:05:25 +0200 Subject: [PATCH] Don't call LoadOpenSimLibrary("osimActuators") in tests Based on comments and commits these calls exist because the osimActuators shared library "is not automatically loaded on anything other than clang". The reason for this is that the tests in question do not actually reference anything in osimActuators directly (e.g., call any of its functions) so the linker sees this and decides there's no need to record the dependency in the executable. And thus osimActuators is not loaded when the executable is run. If we instead just call one of its functions the linker will record the dependency in the test executable and the osimActuators library will get loaded automatically. Given that the only reason we need osimActuators is because the data files these tests load contain objects defined in and registered by that library, perhaps the most appropriate function to call would be RegisterTypes_osimActuators(). That works but then we end up registering the osimActuators types twice (first time being when the library is loaded). So I went with just default-instantiating what looks like one of the most common Actuator classes given that we're loading Actuators from the data files. I think there are probably linker-specific methods to make this work but it seems like the above is probably going to be simpler. --- .../Simulation/SimbodyEngine/Test/testJoints.cpp | 11 +++++++---- OpenSim/Simulation/Test/testInitState.cpp | 11 +++++++++-- OpenSim/Simulation/Test/testModelInterface.cpp | 9 +++++++-- OpenSim/Simulation/Test/testMomentArms.cpp | 2 -- OpenSim/Simulation/Test/testSimulationUtilities.cpp | 9 +++++++-- OpenSim/Simulation/Test/testStatesTrajectory.cpp | 13 ++++++++----- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/OpenSim/Simulation/SimbodyEngine/Test/testJoints.cpp b/OpenSim/Simulation/SimbodyEngine/Test/testJoints.cpp index 4b9121fce5..d0888ff44e 100644 --- a/OpenSim/Simulation/SimbodyEngine/Test/testJoints.cpp +++ b/OpenSim/Simulation/SimbodyEngine/Test/testJoints.cpp @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -69,6 +68,7 @@ #include #include #include +#include #include #include @@ -2059,9 +2059,12 @@ TEST_CASE("testEquivalentBodyForceFromGeneralizedForce") { "===" << endl; - // Need to load osim actuators because the following model has - // Actuators that will fail to register and the model will not load. - LoadOpenSimLibrary("osimActuators"); + // The following model(s) contains Actuators that are registered when the + // osimActuators library is loaded. But unless we call at least one + // function defined in the osimActuators library, some linkers will omit + // its dependency from the executable and it will not be loaded at + // startup. + { PointActuator t; } Model gaitModel("testJointConstraints.osim"); diff --git a/OpenSim/Simulation/Test/testInitState.cpp b/OpenSim/Simulation/Test/testInitState.cpp index f959e87336..0d00938710 100644 --- a/OpenSim/Simulation/Test/testInitState.cpp +++ b/OpenSim/Simulation/Test/testInitState.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -41,7 +41,14 @@ using namespace std; TEST_CASE("testStates") { using namespace SimTK; - LoadOpenSimLibrary("osimActuators"); + + // The following model(s) contains Actuators that are registered when the + // osimActuators library is loaded. But unless we call at least one + // function defined in the osimActuators library, some linkers will omit + // its dependency from the executable and it will not be loaded at + // startup. + { PointActuator t; } + //========================================================================== // Setup OpenSim model std::string modelFile = "arm26.osim"; diff --git a/OpenSim/Simulation/Test/testModelInterface.cpp b/OpenSim/Simulation/Test/testModelInterface.cpp index 1500021508..16c2743728 100644 --- a/OpenSim/Simulation/Test/testModelInterface.cpp +++ b/OpenSim/Simulation/Test/testModelInterface.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include @@ -37,7 +37,12 @@ void testModelTopologyErrors(); void testDoesNotSegfaultWithUnusualConnections(); int main() { - LoadOpenSimLibrary("osimActuators"); + // The following model(s) contains Actuators that are registered when the + // osimActuators library is loaded. But unless we call at least one + // function defined in the osimActuators library, some linkers will omit + // its dependency from the executable and it will not be loaded at + // startup. + { PointActuator t; } SimTK_START_TEST("testModelInterface"); SimTK_SUBTEST(testModelFinalizePropertiesAndConnections); diff --git a/OpenSim/Simulation/Test/testMomentArms.cpp b/OpenSim/Simulation/Test/testMomentArms.cpp index ab9af57578..20c8a02212 100644 --- a/OpenSim/Simulation/Test/testMomentArms.cpp +++ b/OpenSim/Simulation/Test/testMomentArms.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include "SimulationComponentsForTesting.h" @@ -59,7 +58,6 @@ void testMomentArmsAcrossCompoundJoint(); int main() { clock_t startTime = clock(); - LoadOpenSimLibrary("osimActuators"); Object::registerType(CompoundJoint()); try { diff --git a/OpenSim/Simulation/Test/testSimulationUtilities.cpp b/OpenSim/Simulation/Test/testSimulationUtilities.cpp index 4dc7cb895c..c3c816c17f 100644 --- a/OpenSim/Simulation/Test/testSimulationUtilities.cpp +++ b/OpenSim/Simulation/Test/testSimulationUtilities.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include using namespace OpenSim; using namespace std; @@ -33,7 +33,12 @@ using namespace std; void testUpdatePre40KinematicsFor40MotionType(); int main() { - LoadOpenSimLibrary("osimActuators"); + // The following model(s) contains Actuators that are registered when the + // osimActuators library is loaded. But unless we call at least one + // function defined in the osimActuators library, some linkers will omit + // its dependency from the executable and it will not be loaded at + // startup. + { PointActuator t; } SimTK_START_TEST("testSimulationUtilities"); SimTK_SUBTEST(testUpdatePre40KinematicsFor40MotionType); diff --git a/OpenSim/Simulation/Test/testStatesTrajectory.cpp b/OpenSim/Simulation/Test/testStatesTrajectory.cpp index aa150dc55a..fb5dad9b34 100644 --- a/OpenSim/Simulation/Test/testStatesTrajectory.cpp +++ b/OpenSim/Simulation/Test/testStatesTrajectory.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -776,10 +776,13 @@ void testExport() { int main() { SimTK_START_TEST("testStatesTrajectory"); - // actuators library is not loaded automatically (unless using clang). - #if !defined(__clang__) - LoadOpenSimLibrary("osimActuators"); - #endif + + // The following model(s) contains Actuators that are registered when the + // osimActuators library is loaded. But unless we call at least one + // function defined in the osimActuators library, some linkers will omit + // its dependency from the executable and it will not be loaded at + // startup. + { PointActuator t; } // Make sure the states Storage file doesn't already exist; we'll // generate it later and we don't want to use a stale one by accident.