diff --git a/src/cltools/Driver.cpp b/src/cltools/Driver.cpp
index 7b0a579c24356953065f080641e72874efd3c8bd..402a3c4ff11094b6c23d3a0d5882236e149d3c5e 100644
--- a/src/cltools/Driver.cpp
+++ b/src/cltools/Driver.cpp
@@ -41,9 +41,10 @@
  */
 #include "molfile/libmolfile_plugin.h"
 #include "molfile/molfile_plugin.h"
+using namespace PLMD::molfile;
 #else
-#include "libmolfile_plugin.h"
-#include "molfile_plugin.h"
+#include <libmolfile_plugin.h>
+#include <molfile_plugin.h>
 #endif
 #endif
 
diff --git a/src/molfile/Gromacs.h b/src/molfile/Gromacs.h
index fe3d9b6d7d665d2ef845ed20d20a9cbc10dd24e7..b64fe7f40f1a00ed8146b97df7b39ce51da176bc 100644
--- a/src/molfile/Gromacs.h
+++ b/src/molfile/Gromacs.h
@@ -85,6 +85,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 
 #include "endianswap.h"
 
+namespace PLMD{
+namespace molfile{
+
 #if defined(WIN32) || defined(WIN64)
 #define strcasecmp stricmp
 #endif
@@ -1989,5 +1992,7 @@ static int xtc_3dfcoord(md_file *mf, float *fp, int *size, float *precision) {
 	}
 	return 1;
 }
+}
+}
 #endif
 #endif
diff --git a/src/molfile/Makefile b/src/molfile/Makefile
index 4079d510f28ed38be7bae5bcad2beb6c63f2a479..e63adba32e7b1a7cca3ed7934a17335a92299173 100644
--- a/src/molfile/Makefile
+++ b/src/molfile/Makefile
@@ -9,13 +9,8 @@
 
 USE=
 
-
 include ../maketools/make.module
 
-OBJ=dcdplugin.o gromacsplugin.o pdbplugin.o
-
-obj: $(OBJ)
-
 # Local rules for molfile plugins - replacement is delayed 
 CPPFLAGS+=-DSTATIC_PLUGIN  -DVMDPLUGIN=molfile_$(patsubst %.o,%,$@)
 
diff --git a/src/molfile/dcdplugin.cpp b/src/molfile/dcdplugin.cpp
index b7312a2100da440de750090b9641167589805096..7d2022a8ea8b0e6780639552b951e370dec73b1a 100644
--- a/src/molfile/dcdplugin.cpp
+++ b/src/molfile/dcdplugin.cpp
@@ -92,6 +92,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include "endianswap.h"
 #include "molfile_plugin.h"
 
+namespace PLMD{
+namespace molfile{
+
 #ifndef M_PI_2
 #define M_PI_2 1.57079632679489661922
 #endif
@@ -1211,6 +1214,9 @@ VMDPLUGIN_API int VMDPLUGIN_fini() {
   return VMDPLUGIN_SUCCESS;
 }
 
+}
+}
+
   
 #ifdef TEST_DCDPLUGIN
 
diff --git a/src/molfile/endianswap.h b/src/molfile/endianswap.h
index 71aa93238aa1ef54507df4bb96f64cc9f4eba585..ff9560ce82ef4b16377595db2be04e6953818d91 100644
--- a/src/molfile/endianswap.h
+++ b/src/molfile/endianswap.h
@@ -36,6 +36,8 @@ OTHER DEALINGS WITH THE SOFTWARE.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #ifndef __PLUMED_molfile_endianswap_h
 #define __PLUMED_molfile_endianswap_h
+namespace PLMD{
+namespace molfile{
 /***************************************************************************
  *cr
  *cr            (C) Copyright 1995-2009 The Board of Trustees of the
@@ -208,5 +210,6 @@ void mdio_swap8(double *i) {
 #endif
 
 #endif
-
+}
+}
 #endif
diff --git a/src/molfile/fastio.h b/src/molfile/fastio.h
index 85e00f3ebf8de4f1c8bd284964a40e8fadc0bec7..addaded253d5565dac576e89669d72ec5c33ec47 100644
--- a/src/molfile/fastio.h
+++ b/src/molfile/fastio.h
@@ -75,6 +75,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include <string.h>
 #include <windows.h>
 
+namespace PLMD{
+namespace molfile{
+
 typedef HANDLE fio_fd;
 typedef LONGLONG fio_size_t;
 typedef void * fio_caddr_t;
@@ -360,6 +363,9 @@ static fio_size_t fio_ftell(fio_fd fd) {
 }
 #endif /* plain ANSI C */
 
+}
+}
+
 #else 
 
 /* Version for UNIX machines */
@@ -375,6 +381,9 @@ static fio_size_t fio_ftell(fio_fd fd) {
 #include <fcntl.h>
 #include <string.h>
 
+namespace PLMD{
+namespace molfile{
+
 typedef int fio_fd;
 typedef off_t fio_size_t;      /* off_t is 64-bits with LFS builds */
 
@@ -397,22 +406,36 @@ typedef off_t fio_size_t;      /* off_t is 64-bits with LFS builds */
 
 typedef void * fio_caddr_t;
 
+}
+}
+
 #if defined(USE_KERNEL_READV)
 #include <errno.h>
 #include <sys/uio.h>
+namespace PLMD{
+namespace molfile{
 typedef struct iovec fio_iovec;
+}
+}
 #else
 
+namespace PLMD{
+namespace molfile{
 typedef struct {
   fio_caddr_t iov_base;
   int iov_len;
 } fio_iovec;
+}
+}
 #endif
 
 #define FIO_SEEK_CUR SEEK_CUR
 #define FIO_SEEK_SET SEEK_SET
 #define FIO_SEEK_END SEEK_END
 
+namespace PLMD{
+namespace molfile{
+
 static int fio_open(const char *filename, int mode, fio_fd *fd) {
   int nfd;
   int oflag = 0;
@@ -621,8 +644,14 @@ static fio_size_t fio_ftell(fio_fd fd) {
   return lseek(fd, 0, SEEK_CUR);
 }
 
+}
+}
+
 #endif
 
+namespace PLMD{
+namespace molfile{
+
 
 /* higher level routines that are OS independent */
 
@@ -639,4 +668,6 @@ static int fio_write_str(fio_fd fd, const char *str) {
   return (fio_fwrite((void *) str, len, 1, fd) != 1);
 }
 
+}
+}
 #endif
diff --git a/src/molfile/gromacsplugin.cpp b/src/molfile/gromacsplugin.cpp
index 5e4a0142d3edad539392c345f59e4e67ebf7fd60..0259bc7f3002835b8b07c8658ba8651d300106d4 100644
--- a/src/molfile/gromacsplugin.cpp
+++ b/src/molfile/gromacsplugin.cpp
@@ -66,6 +66,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include <strings.h>
 #endif
 
+namespace PLMD{
+namespace molfile{
+
 #ifndef M_PI
 #define M_PI           3.14159265358979323846
 #endif
@@ -791,6 +794,9 @@ VMDPLUGIN_API int VMDPLUGIN_fini() {
   return 0;
 }
 
+}
+}
+
 
 #ifdef TEST_G96_PLUGIN
 
diff --git a/src/molfile/largefiles.h b/src/molfile/largefiles.h
index 5ba4c598e5aa25795a029a93a0f9ba63d30d1cf8..fafcbe7fd72d5e0e33cf66cf5fcce50090554e80 100644
--- a/src/molfile/largefiles.h
+++ b/src/molfile/largefiles.h
@@ -36,6 +36,8 @@ OTHER DEALINGS WITH THE SOFTWARE.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #ifndef __PLUMED_molfile_largefiles_h
 #define __PLUMED_molfile_largefiles_h
+namespace PLMD{
+namespace molfile{
 /***************************************************************************
  *cr
  *cr            (C) Copyright 1995-2009 The Board of Trustees of the
@@ -71,5 +73,6 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #endif
 #define _FILE_OFFSET_BITS 64
 #endif
-
+}
+}
 #endif
diff --git a/src/molfile/libmolfile_plugin.h b/src/molfile/libmolfile_plugin.h
index 7200abfbb48481d4f6a64d2bff32cf13fbd01452..decef25e12dff46b3e31c731454ea65b80f3c8f7 100644
--- a/src/molfile/libmolfile_plugin.h
+++ b/src/molfile/libmolfile_plugin.h
@@ -37,20 +37,19 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #ifndef __PLUMED_molfile_libmolfile_plugin_h
 #define __PLUMED_molfile_libmolfile_plugin_h
 #include "vmdplugin.h"
+namespace PLMD{
+namespace molfile{
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
-extern int molfile_dcdplugin_init(void);
-extern int molfile_dcdplugin_register(void *, vmdplugin_register_cb);
-extern int molfile_dcdplugin_fini(void);
-extern int molfile_gromacsplugin_init(void);
-extern int molfile_gromacsplugin_register(void *, vmdplugin_register_cb);
-extern int molfile_gromacsplugin_fini(void);
-extern int molfile_pdbplugin_init(void);
-extern int molfile_pdbplugin_register(void *, vmdplugin_register_cb);
-extern int molfile_pdbplugin_fini(void);
+ int molfile_dcdplugin_init(void);
+ int molfile_dcdplugin_register(void *, vmdplugin_register_cb);
+ int molfile_dcdplugin_fini(void);
+ int molfile_gromacsplugin_init(void);
+ int molfile_gromacsplugin_register(void *, vmdplugin_register_cb);
+ int molfile_gromacsplugin_fini(void);
+ int molfile_pdbplugin_init(void);
+ int molfile_pdbplugin_register(void *, vmdplugin_register_cb);
+ int molfile_pdbplugin_fini(void);
 
 #define MOLFILE_INIT_ALL \
     molfile_dcdplugin_init(); \
@@ -67,7 +66,6 @@ extern int molfile_pdbplugin_fini(void);
     molfile_gromacsplugin_fini(); \
     molfile_pdbplugin_fini(); \
 
-#ifdef __cplusplus
 }
-#endif
+}
 #endif
diff --git a/src/molfile/molfile_plugin.h b/src/molfile/molfile_plugin.h
index 5ed06d090bdab9dfd7da7665ad4891aad16429b3..9f6572014a9dc1011d6d09c48db5b2008af52ee4 100644
--- a/src/molfile/molfile_plugin.h
+++ b/src/molfile/molfile_plugin.h
@@ -63,6 +63,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 
 #include "vmdplugin.h"
 
+namespace PLMD{
+namespace molfile{
+
 #if defined(DESRES_READ_TIMESTEP2)
 /* includes needed for large integer types used for frame counts */
 #include <sys/types.h>
@@ -957,6 +960,8 @@ typedef struct {
 
 } molfile_plugin_t;
 
+}
+}
 #endif
 
 #endif
diff --git a/src/molfile/pdbplugin.cpp b/src/molfile/pdbplugin.cpp
index 58badea6b14f30d722e8bfc01d15db3c45d6f66c..ebd44a72efeea979d61b7761eba1f2e7773f87fa 100644
--- a/src/molfile/pdbplugin.cpp
+++ b/src/molfile/pdbplugin.cpp
@@ -66,6 +66,10 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdlib.h>
 #include <string.h>
 
+namespace PLMD{
+namespace molfile{
+
+
 /*
  * API functions start here
  */
@@ -639,4 +643,7 @@ VMDPLUGIN_API int VMDPLUGIN_fini() {
   return VMDPLUGIN_SUCCESS;
 }
 
+}
+}
+
 #endif
diff --git a/src/molfile/periodic_table.h b/src/molfile/periodic_table.h
index 7545da7c32d861cc71222fa6e7e978b5f96f748b..6055a8232612e9785292cdf24e645673160b0eb6 100755
--- a/src/molfile/periodic_table.h
+++ b/src/molfile/periodic_table.h
@@ -57,6 +57,8 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include <string.h>
 #include <ctype.h>
 
+namespace PLMD{
+namespace molfile{
 /* periodic table of elements for translation of ordinal to atom type */
 static const char *pte_label[] = { 
     "X",  "H",  "He", "Li", "Be", "B",  "C",  "N",  "O",  "F",  "Ne",
@@ -241,4 +243,6 @@ int main() {
   return 0;
 }
 #endif
+}
+}
 #endif
diff --git a/src/molfile/readpdb.h b/src/molfile/readpdb.h
index 9498184aae72a5d0c8ac9c5fc849cd158e4e79da..f81173003fe28c0c6fc088c87dcb2527d535a3ee 100755
--- a/src/molfile/readpdb.h
+++ b/src/molfile/readpdb.h
@@ -60,6 +60,9 @@ OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdlib.h>
 #include <string.h>
 
+namespace PLMD{
+namespace molfile{
+
 #define PDB_RECORD_LENGTH   80   /* actual record size */
 #define PDB_BUFFER_LENGTH   83   /* size need to buffer + CR, LF, and NUL */
 
@@ -438,5 +441,7 @@ static int write_raw_pdb_record(FILE *fd, const char *recordname,
   return (rc > 0);
 }
 
+}
+}
 #endif
 #endif
diff --git a/src/molfile/vmdplugin.h b/src/molfile/vmdplugin.h
index 42ecd1240f5870434b4e12d1576ff8dd23405161..a8fea2cac35bdadf6352997edcdbb22ac425fb8a 100644
--- a/src/molfile/vmdplugin.h
+++ b/src/molfile/vmdplugin.h
@@ -36,6 +36,8 @@ OTHER DEALINGS WITH THE SOFTWARE.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #ifndef __PLUMED_molfile_vmdplugin_h
 #define __PLUMED_molfile_vmdplugin_h
+namespace PLMD{
+namespace molfile{
 /***************************************************************************
  *cr
  *cr            (C) Copyright 1995-2006 The Board of Trustees of the
@@ -99,7 +101,12 @@ OTHER DEALINGS WITH THE SOFTWARE.
 /** "WIN32" is defined on both WIN32 and WIN64 platforms... */
 #if (defined(WIN32)) 
 #define WIN32_LEAN_AND_MEAN
+}
+}
 #include <windows.h>
+namespace PLMD{
+namespace molfile{
+
 
 #if !defined(STATIC_PLUGIN)
 #if defined(VMDPLUGIN_EXPORTS)
@@ -127,12 +134,9 @@ BOOL APIENTRY DllMain( HANDLE hModule,
 #define VMDPLUGIN_API 
 #endif
 
+//TONI  Plumed mod: never "extern", C++ namespace
 /** define plugin linkage correctly for both C and C++ based plugins */
-#ifdef __cplusplus
-#define VMDPLUGIN_EXTERN extern "C" VMDPLUGIN_API
-#else
-#define VMDPLUGIN_EXTERN extern VMDPLUGIN_API
-#endif  /* __cplusplus */
+#define VMDPLUGIN_EXTERN VMDPLUGIN_API
 
 /* 
  * Plugin API functions start here 
@@ -227,4 +231,6 @@ VMDPLUGIN_EXTERN int VMDPLUGIN_register_tcl(void *, void *tcl_interp,
 VMDPLUGIN_EXTERN int VMDPLUGIN_fini(void);
 
 #endif   /* VMD_PLUGIN_H */
+}
+}
 #endif