Commit a06959c0 authored by Timothee Habra's avatar Timothee Habra
Browse files

load dynamically symbolic function in linux

parent d169b067
......@@ -30,7 +30,7 @@ set(INCLUDE_DIR ${INCLUDE_DIR} ${PROJECT_SOURCE_DIR} PARENT_SCOPE)
increment_void_symbolic( symbolicR )
include (GenerateExportHeader)
add_library(project_symbolic ${SOURCE_FILES} ${INCLUDE_DIR})
add_library(project_symbolic SHARED ${SOURCE_FILES} ${INCLUDE_DIR})
GENERATE_EXPORT_HEADER( project_symbolic )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
......
......@@ -116,12 +116,11 @@ add_subdirectory( ${PROJECT_SOURCE_DIR}/../userfctR ${CMAKE_CURRENT_BINARY_DIR}/
if (NOT FLAG_SEPARATE_SYMBOLIC)
#increment_src( ${PROJECT_SOURCE_DIR}/../symbolicR )
#increment_void_symbolic( symbolicR )
add_subdirectory( ${PROJECT_SOURCE_DIR}/../symbolicR ${CMAKE_CURRENT_BINARY_DIR}/symbolicR)
endif ( )
#increment_void_symbolic( symbolicR )
# list include directories (to find headers)
init_include()
......@@ -159,7 +158,7 @@ if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries
else ( )
target_link_libraries( ${Executable} MBsysC_loadXML MBsysC_module project_symbolic)
target_link_libraries( ${Executable} MBsysC_loadXML MBsysC_module )
if (NOT FLAG_SHARED_LIB)
......@@ -184,6 +183,10 @@ else ( )
endif ( )
if (UNIX)
target_link_libraries ( ${Executable} dl )
endif ( )
endif ( )
# separate symbolic files compilation
......
......@@ -86,9 +86,22 @@ int main(int argc, char const *argv[])
return 0;
}
#ifdef UNIX
#include <dlfcn.h> // linux function to dynamically load libraries
#endif
void mbs_get_project_functions(MbsData *mbs_data)
{
void *lib_handle;
char *error;
lib_handle = dlopen(PROJECT_SOURCE_DIR"/build/symbolicR/libproject_symbolic.so", RTLD_LAZY);
if (!lib_handle)
{
fprintf(stderr, "%s\n", dlerror());
exit(1);
}
// user function pointers
mbs_data->user_JointForces = user_JointForces;
mbs_data->user_init = user_init;
......@@ -98,6 +111,7 @@ void mbs_get_project_functions(MbsData *mbs_data)
mbs_data->user_DrivenJoints = user_DrivenJoints;
mbs_data->user_cons_hJ = user_cons_hJ;
mbs_data->user_cons_jdqd = user_cons_jdqd;
mbs_data->user_LinkForces = user_LinkForces;
#ifdef REAL_TIME
mbs_data->user_realtime_options = user_realtime_options;
......@@ -115,11 +129,27 @@ void mbs_get_project_functions(MbsData *mbs_data)
#endif
// symbolic function pointers
mbs_data->mbs_link = mbs_link;
mbs_data->mbs_link3D = mbs_link3D;
mbs_data->mbs_extforces = mbs_extforces;
mbs_data->mbs_accelred = mbs_accelred;
mbs_data->mbs_dirdyna = mbs_dirdyna;
mbs_data->mbs_cons_hJ = mbs_cons_hJ;
mbs_data->mbs_cons_jdqd = mbs_cons_jdqd;
}
\ No newline at end of file
//mbs_data->mbs_link = mbs_link;
//mbs_data->mbs_link3D = mbs_link3D;
//mbs_data->mbs_extforces = mbs_extforces;
//mbs_data->mbs_accelred = mbs_accelred;
//mbs_data->mbs_dirdyna = mbs_dirdyna;
//mbs_data->mbs_cons_hJ = mbs_cons_hJ;
//mbs_data->mbs_cons_jdqd = mbs_cons_jdqd;
mbs_data->mbs_link = dlsym(lib_handle, "mbs_link");
mbs_data->mbs_link3D = dlsym(lib_handle, "mbs_link3D");
mbs_data->mbs_extforces = dlsym(lib_handle, "mbs_extforces");
mbs_data->mbs_accelred = dlsym(lib_handle, "mbs_accelred");
mbs_data->mbs_dirdyna = dlsym(lib_handle, "mbs_dirdyna");
mbs_data->mbs_cons_hJ = dlsym(lib_handle, "mbs_cons_hJ");
mbs_data->mbs_cons_jdqd = dlsym(lib_handle, "mbs_cons_jdqd");
if ((error = dlerror()) != NULL)
{
fprintf(stderr, "%s\n", error);
exit(1);
}
// note : no need to call dlclose(), the library will be automatically closed at the end of the execution
}
......@@ -129,6 +129,7 @@ struct MbsData
user_DrivenJoints_ptr user_DrivenJoints;
user_cons_hJ_ptr user_cons_hJ;
user_cons_jdqd_ptr user_cons_jdqd;
user_LinkForces_ptr user_LinkForces;
#ifdef REAL_TIME
user_realtime_options_ptr user_realtime_options;
......
......@@ -19,6 +19,8 @@ typedef void (*user_Derivative_ptr)(MbsData *s);
typedef void (*user_DrivenJoints_ptr)(MbsData *s, double tsim);
typedef void (*user_cons_hJ_ptr)(double *h, double **Jac, MbsData *s, double tsim);
typedef void (*user_cons_jdqd_ptr)(double *jdqd, MbsData *s, double tsim);
typedef double (*user_LinkForces_ptr)(double Z, double Zd, MbsData *mbs_data, double tsim, int ilnk);
#ifdef REAL_TIME
typedef struct Realtime_option Realtime_option;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment