From 2748878e9fd690bd10b5b613140b692df590af80 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 6 Feb 2004 04:20:13 +0000 Subject: [PATCH] Fix yet another linker error on OS X This commit was SVN r655. --- src/mpi/communicator/communicator.h | 3 +++ src/mpi/communicator/lam_comm_init.c | 12 ++++++++++++ src/tools/laminfo/laminfo.cc | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/mpi/communicator/communicator.h b/src/mpi/communicator/communicator.h index 3c37fd00c2..44f23caf0a 100644 --- a/src/mpi/communicator/communicator.h +++ b/src/mpi/communicator/communicator.h @@ -11,6 +11,7 @@ #include "mpi/group/group.h" #include "mca/mpi/coll/coll.h" + struct lam_communicator_t { char c_name[MPI_MAX_OBJECT_NAME]; uint32_t c_contextid; @@ -69,10 +70,12 @@ static inline lam_proc_t* lam_comm_lookup_peer(lam_communicator_t* comm, size_t return comm->c_remote_group->g_procs[peer_id]; } + #if defined(c_plusplus) || defined(__cplusplus) extern "C" { #endif int lam_comm_init(lam_communicator_t *comm); + int lam_comm_link_function(void); #if defined(c_plusplus) || defined(__cplusplus) } #endif diff --git a/src/mpi/communicator/lam_comm_init.c b/src/mpi/communicator/lam_comm_init.c index f9db51c44f..93620d364b 100644 --- a/src/mpi/communicator/lam_comm_init.c +++ b/src/mpi/communicator/lam_comm_init.c @@ -21,6 +21,18 @@ lam_communicator_t lam_mpi_comm_world; lam_communicator_t lam_mpi_comm_self; +/* + * This function is here solely to allow non MPI progrlams be able to + * have the globals listed above linked in (e.g., laminfo). According + * to POSIX, we have to link in a function to guarantee that we can + * get the global symbols in the relevant .o file. + */ +int lam_comm_link_function(void) +{ + return LAM_SUCCESS; +} + + /* * This is a shell function that needs to be filled in. It is here so * that this file will get linked into MPI executables (POSIX says diff --git a/src/tools/laminfo/laminfo.cc b/src/tools/laminfo/laminfo.cc index bc5303ff50..7d0c29d43b 100644 --- a/src/tools/laminfo/laminfo.cc +++ b/src/tools/laminfo/laminfo.cc @@ -19,6 +19,7 @@ #include "lam/runtime/runtime.h" #include "lam/util/output.h" #include "lam/util/cmd_line.h" +#include "mpi/communicator/communicator.h" #include "mca/lam/base/base.h" #include "tools/laminfo/laminfo.h" @@ -224,14 +225,15 @@ laminfo::type_vector_t laminfo::mca_types; int main(int argc, char *argv[]) { - int ret; + int ret = 0; bool acted = false; bool want_all = false; // Start LAM process - if (LAM_SUCCESS != lam_init(argc, argv)) + if (LAM_SUCCESS != lam_init(argc, argv)) { return -1; + } // Initialize the argv parsing handle @@ -265,6 +267,17 @@ int main(int argc, char *argv[]) lam_cmd_line_make_opt(cmd_line, 'a', "all", 0, "Show all configuration options and MCA parameters"); + // Call some useless functions in order to guarantee to link in some + // global variables. Only check the return value so that the + // compiler doesn't optimize out the useless function. + + if (LAM_SUCCESS != lam_comm_link_function()) { + // Stop .. or I'll say stop again! + ++ret; + } else { + --ret; + } + // Get MCA parameters, if any */ mca_base_open();