Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#1199 closed task (fixed)

Investigate how to force static linking of FMUs (Kinsol, gfortran, blas, lapack)

Reported by: Christian Andersson Owned by: Jesper Mattsson
Priority: major Milestone: 1.6.x
Component: FMI/Export Version: trunk
Keywords: Cc:

Description (last modified by jakesson)

Static linking is needed when we compile our FMUs with Kinsol. This applies also to other shared libraries, including gfortran, see #1559.

Part of ticket:1196

Change History (23)

comment:1 Changed 9 years ago by Christian Andersson

The option -static to gcc seems to be a good candidate :)

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (option -static)

comment:2 Changed 9 years ago by Christian Andersson

Static linking versus libsundials_kinsol and libsundials_nvecserial can be achieved by providing the full paths. Static libraries are built by default when installing Sundials even when providing the enable shared flag to Sundials. To statically link gfortran, we could use -static-libgfortran.

comment:3 Changed 9 years ago by jakesson

Resolution: fixed
Status: newclosed

FMUs generated from Python runs fine on machines without JModelica.org installed, closing.

comment:4 Changed 8 years ago by jakesson

Milestone: 1.5.01.6.x
Resolution: fixed
Status: closedreopened

We need to reopen this one. The configure script checks that static libs for Sundials are present, but if dynamic libs are also present, then FMUs are linked against the dynamic libs. As a consequence, the FMUs are not portable from one machine to another, which is not according to spec. I tried the '-static' flag to the linker on my Mac, but then I got linking errors:

make -f /Users/jakesson/packages/jm-install/Makefiles/MakeFile JMI_AD=JMI_AD_NONE model
gcc -g -O2 -std=c89 -pedantic -DJMI_AD=JMI_AD_NONE -fPIC -static -static-libgcc -I/Users/jakesson/packages/jm-install/include  -I/Users/jakesson/packages/Sundials/sundials-2.4.0-install-non-shared/include -c -o CCodeGenTests_BlockTest2.o sources/CCodeGenTests_BlockTest2.c
In file included from /Users/jakesson/packages/jm-install/include/jmi_common.h:202:0,
                 from /Users/jakesson/packages/jm-install/include/jmi.h:293,
                 from sources/CCodeGenTests_BlockTest2.c:4:
/Users/jakesson/packages/jm-install/include/jmi_array_none.h:57:35: warning: anonymous variadic macros were introduced in C99
/Users/jakesson/packages/jm-install/include/jmi_array_none.h:64:53: warning: anonymous variadic macros were introduced in C99
/Users/jakesson/packages/jm-install/include/jmi_array_none.h:71:36: warning: anonymous variadic macros were introduced in C99
/Users/jakesson/packages/jm-install/include/jmi_array_none.h:79:54: warning: anonymous variadic macros were introduced in C99
sources/CCodeGenTests_BlockTest2.c:79:18: warning: ISO C forbids zero-size array 'Output_vrefs'
sources/CCodeGenTests_BlockTest2.c:79:36: warning: ISO C forbids empty initializer braces
mkdir -p binaries/darwin64
gcc -dynamiclib -g -O2 -std=c89 -pedantic -DJMI_AD=JMI_AD_NONE -fPIC -static -static-libgcc -o binaries/darwin64/CCodeGenTests_BlockTest2.dylib CCodeGenTests_BlockTest2.o -L/Users/jakesson/packages/jm-install/lib -lgfortran -ljmi -lfmi -lmodelica_utilities -llapack -lblas -L/Users/jakesson/packages/Sundials/sundials-2.4.0-install-non-shared/lib -lsundials_kinsol -lsundials_nvecserial  
Undefined symbols:
  "_strncpy", referenced from:
      _fmi_instantiate_model in libfmi.a(libfmi_la-fmi.o)
      _fmi_instantiate_model in libfmi.a(libfmi_la-fmi.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
  "_putchar", referenced from:
      _jmi_divide in libjmi.a(libjmi_la-jmi_common.o)
  "_sin", referenced from:
      _dae_init_block_0 in CCodeGenTests_BlockTest2.o
      _dae_block_1 in CCodeGenTests_BlockTest2.o
  "_memcpy", referenced from:
      _fmi_set_continuous_states in libfmi.a(libfmi_la-fmi.o)
      _fmi_get_derivatives in libfmi.a(libfmi_la-fmi.o)
      _fmi_get_continuous_states in libfmi.a(libfmi_la-fmi.o)
      _fmi_get_nominal_continuous_states in libfmi.a(libfmi_la-fmi.o)
      _fmi_get_state_value_references in libfmi.a(libfmi_la-fmi.o)
  "_puts", referenced from:
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _kinPinvSolve in libjmi.a(libjmi_la-kinpinv.o)
  "_fprintf", referenced from:
      _jmi_log in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_log in libjmi.a(libjmi_la-jmi_util.o)
  "_free", referenced from:
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_delete in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_opt_set_p_opt_indices in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_delete in libjmi.a(libjmi_la-jmi.o)
      _jmi_ode_f in libjmi.a(libjmi_la-jmi.o)
      _jmi_ode_df_n_nz in libjmi.a(libjmi_la-jmi.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_first_fit in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_get_connection_length in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_get_connections in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _kinPinvFree in libjmi.a(libjmi_la-kinpinv.o)
      _KINPinv in libjmi.a(libjmi_la-kinpinv.o)
      _KINPinv in libjmi.a(libjmi_la-kinpinv.o)
      _KINPinv in libjmi.a(libjmi_la-kinpinv.o)
      _KINPinv in libjmi.a(libjmi_la-kinpinv.o)
     (maybe you meant: _fmi_free_model_instance)
  "_calloc", referenced from:
      _fmi_get_jacobian_fd in libfmi.a(libfmi_la-fmi.o)
      _fmi_get_jacobian_fd in libfmi.a(libfmi_la-fmi.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_fd_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_dae_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_sim_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_block_residual in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_new_color_info in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_func_cad_dF in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_init_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_opt_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_opt_set_p_opt_indices in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_init in libjmi.a(libjmi_la-jmi.o)
      _jmi_ode_f in libjmi.a(libjmi_la-jmi.o)
      _jmi_ode_df_n_nz in libjmi.a(libjmi_la-jmi.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_directional_FD_dF in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_first_fit in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_get_connection_length in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_get_connections in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_dae_cad_color_graph in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
  "___stdoutp", referenced from:
      _jmi_log in libjmi.a(libjmi_la-jmi_util.o)
  "___sprintf_chk", referenced from:
      _fmi_extract_debug_info in libfmi.a(libfmi_la-fmi.o)
      _fmi_extract_debug_info in libfmi.a(libfmi_la-fmi.o)
      _fmi_extract_debug_info in libfmi.a(libfmi_la-fmi.o)
      _fmi_extract_debug_info in libfmi.a(libfmi_la-fmi.o)
      _kin_info in libjmi.a(libjmi_la-jmi_newton_solvers.o)
      _kin_err in libjmi.a(libjmi_la-jmi_newton_solvers.o)
  "_clock", referenced from:
      _jmi_kinsol_solve in libjmi.a(libjmi_la-jmi_newton_solvers.o)
      _jmi_kinsol_solve in libjmi.a(libjmi_la-jmi_newton_solvers.o)
  "_printf", referenced from:
      _jmi_divide in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_print_summary in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _jmi_util_dae_derivative_checker in libjmi.a(libjmi_la-jmi_util.o)
      _kinPinvSetup in libjmi.a(libjmi_la-kinpinv.o)
  "___stderrp", referenced from:
      _jmi_log in libjmi.a(libjmi_la-jmi_util.o)
  "_strlen", referenced from:
      _fmi_instantiate_model in libfmi.a(libfmi_la-fmi.o)
      _fmi_instantiate_model in libfmi.a(libfmi_la-fmi.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_info_init in libjmi.a(libjmi_la-jmi_common.o)
  "_malloc", referenced from:
      _jmi_func_new in libjmi.a(libjmi_la-jmi_common.o)
      _KINPinvGetReturnFlagName in libjmi.a(libjmi_la-kinsol_jmod.o)
      _KINPinv in libjmi.a(libjmi_la-kinpinv.o)
  "_floor", referenced from:
      _jmi_dround in libjmi.a(libjmi_la-jmi_common.o)
      _jmi_dround in libjmi.a(libjmi_la-jmi_common.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [model] Error 1
make: *** [model_noad] Error 2

One way to overcome this would be to link to the .a files directly.

A problem is then on Ubuntu if Sundials is installed with apt-get, in which case on static libs are installed.

We need to find a way to force static linking in order for the FMUs to be correctly generated. T

comment:5 Changed 8 years ago by Iakov Nakhimovski

Could you try with "-Xlinker -Bstatic" flags? They should come before the libraries list.
As I understand the -static flags just prevents linking with dynamic libs which is not what you want.

comment:6 Changed 8 years ago by jakesson

Description: modified (diff)
Summary: Investigate how to foce static linkaging for KinsolInvestigate how to foce static linking of FMUs (Kinsol, gfortran)

These flags does not work easily on gcc for Mac OS X, see http://stackoverflow.com/questions/844819/how-to-static-link-on-os-x. I also tried the option -Wl,-Bstatic with the same result.

I also tried this on Ubuntu 64 bit, where (only) dynamic Sundials libs are installed using apt-get. However, the -Bstatic flag instructs the linker to choose archive libs if they are available, and since they are not in this case, linking fails. In my understanding it is not possible to link (without hassle) statically against a dynamic library, which is essentially what we try to do here. This is explained in http://stackoverflow.com/questions/725472/static-link-of-shared-library-function-in-gcc

In summary, my conclusions are the following:

  1. We need to provide static libraries for all packages we need to link to, including Sundials/kinsol and gfortran.
  2. In the case of Mac, also the gcc runtime libs need to be available. We could link explicitly to the Sundials archive libs, and thereby force static linking, but chances are that the FMUs will not be portable if we don't link statically also to the gcc runtime libs.
  3. We should not, however, try to statically link the glibc http://stackoverflow.com/questions/809794/use-both-static-and-dynamically-linked-libraries-in-gcc
  4. Unless it is possible to install also static Sundials libraries using apt-get, the precompiled Sundials that comes with apt-get is useless for our purposes. Also, it must not be installed on the system or it will interfere with a user compiled version of Sundials as explained in http://www.jmodelica.org/4002#comment-1643.
  5. These problems apply only to Linux and Mac, since on Windows, (only) static libraries for Sundials and gfortran are provided.

comment:7 Changed 8 years ago by Jesper Mattsson

From the man page of ld (emphasis mine):

-Bstatic
-dn
-non_shared
-static

Do not link against shared libraries. This is only meaningful on
platforms for which shared libraries are supported. The different [...]

and

-l namespec
--library=namespec

Add the archive or object file specified by namespec to the list of
files to link. This option may be used any number of times. If
namespec is of the form :filename, ld will search the library path
for a file called filename, otherwise it will search the library
path for a file called libnamespec.a.

On systems which support shared libraries, ld may also search for
files other than libnamespec.a. Specifically, on ELF and SunOS
systems, ld will search a directory for a library called
libnamespec.so before searching for one called libnamespec.a. (By
convention, a ".so" extension indicates a shared library.) Note
that this behavior does not apply to :filename, which always
specifies a file called filename.

We do not want to prevent linking against shared libraries entirely - not for libraries like libc and libm. We just want to make sure that the libraries we can't expect to be present on a compatible system are statically linked. It seems that changing "-lname" to "-l:lib''name''.a" for the non-standard libraries is what we want.

comment:8 Changed 8 years ago by Jesper Mattsson

Hm, seems formatting failed there - I meant "-l:libname.a".

comment:9 Changed 8 years ago by Jesper Mattsson

Concerning the sundials packages in apt, the one we want is called "libsundials-serial-dev", it contains everything (headers, static libe and shared libs) the other ones only contain the shared libs.

comment:11 Changed 8 years ago by Iakov Nakhimovski

The problem is on my system static libs are not a part of serial-dev package:

iakov@iakov-VirtualBox:~$ apt-file search libsundials_cvode.so
libsundials-cvode1: /usr/lib/libsundials_cvode.so.1
libsundials-cvode1: /usr/lib/libsundials_cvode.so.1.0.0
libsundials-serial-dev: /usr/lib/libsundials_cvode.so
iakov@iakov-VirtualBox:~$ apt-file search libsundials_cvode.a
<not found>

The safe solution is probably to always build Sundials from under ThirdParty. GotoBlas (which is a portable lapack/blas) should probably also go there and be used if no static lapack libs are provided for building FMUs.
To avoid any strange conflicts with preinstalled packages we could use ‘-nodefaultlibs’ and explicitly list all the needed libs (including libc). From manual it seems:

gcc -nodefaultlibs files... ‘gcc -print-libgcc-file-name‘

comment:12 Changed 8 years ago by Jesper Mattsson

Summary: Investigate how to foce static linking of FMUs (Kinsol, gfortran)Investigate how to force static linking of FMUs (Kinsol, gfortran)

comment:13 Changed 8 years ago by jakesson

Proposed solution

  • Require that the user build Sundials from sources
  • Add the -nodefaultlibs to prevent use of Sundials installed in /usr/lib
  • Force static linking
    • -l:libgfortran.a
    • -l:libkinsol.a

comment:14 Changed 8 years ago by jakesson

Owner: changed from Christian Andersson to jakesson
Status: reopenedassigned

comment:15 Changed 8 years ago by Jesper Mattsson

From gcc man page (italics mine):

-nodefaultlibs

Do not use the standard system libraries when linking. Only the
libraries you specify will be passed to the linker, options
specifying linkage of the system libraries, such as
"-static-libgcc" or "-shared-libgcc", will be ignored. The
standard startup files are used normally, unless -nostartfiles is
used. The compiler may generate calls to "memcmp", "memset",
"memcpy" and "memmove". These entries are usually resolved by
entries in libc. These entry points should be supplied through
some other mechanism when this option is specified.

This option affects those libs that are always linked in even if you don't add -l flags for them. Clearly that does not include Sundials.

comment:16 Changed 8 years ago by Jesper Mattsson

changeset:2790

Changed FMU/JMU makefile to require static linking of Sundials and Fortran libs. (ticket reference missing in commit comment)

comment:17 Changed 8 years ago by jakesson

Summary: Investigate how to force static linking of FMUs (Kinsol, gfortran)Investigate how to force static linking of FMUs (Kinsol, gfortran, blas, lapack)

The -l:libfoo.a construct does not work on Mac, so there we have to resort to explicitly stating the libraries with absolute paths. For Kinsol, Blas and Lapack this works fine, but for libgfortran.a this is troublesome. On my system, libgfortran.a resides in /opt/local/lib, but this need not be the case.

comment:18 Changed 8 years ago by jakesson

changeset:2801:

Added static linking of Kinsol, Blas, Lapack on Mac OS X, see #1199.

comment:19 Changed 8 years ago by jakesson

changeset:2803:

Updated the Windows makefile for compiled code to ensure static linking. This is a precaution, it actually works alrady since we only have static libs for blas, lapack, sundials and gfortran. See #1199.

comment:20 Changed 8 years ago by jakesson

Owner: changed from jakesson to Jesper Mattsson

The two things that remains here are:

  • Static linking with gfortran on Mac, see #1594.
  • Static linking with blas and lapack on Linux.

Reassigning to Jesper.

comment:21 Changed 8 years ago by Jesper Mattsson

I ran into a problem on a 64-bit Ubuntu - the system libgfortran.a was compiled without -fPIC, leading to the FMU compilation failing with an error message about the code not being relocatable.

I can't see a way around that without either requiring users to compile their own GCC. Compiling our own libgfortran.a seems unfeasible, since it has to match the installed GCC version.

comment:22 Changed 8 years ago by Jesper Mattsson

Resolution: fixed
Status: assignedclosed

changeset:2818

  • Removed forced static linking of libgfortran on Linux.
  • Added forced static linking of libblas & liblapack on Linux.
  • Made it easier to set CFLAGS/CXXFLAGS when using Makefile.linux by using += for most of it.

comment:23 Changed 8 years ago by jakesson

Component: FMIFMI/Export
Note: See TracTickets for help on using tickets.