diff --git a/Solver/function.cpp b/Solver/function.cpp
index 07c7f050a5310675453a8e347d03ddaf304b4698..8e73c0849763b86aaa6cd9d67d0ad7e3597b7666 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -599,27 +599,26 @@ class functionLua : public function {
 #endif
 
 // functionC
-
-void functionC::buildLibrary(std::string code, std::string filename) 
-{
-  //todo use CMAKE_CXX_COMPILER
-  //todo use clean temporary file names
-  //todo work on windows :-)
-  //todo if DG_BUILD_DIR is not defined, use the directory used at compilation time
-  FILE *tmpSrc = fopen("_tmpSrc.cpp","w");
-  fprintf(tmpSrc, "%s\n",code.c_str());
-  fclose(tmpSrc);
+void functionC::buildLibraryFromFile(const std::string cfilename, const std::string libfilename) {
   FILE *tmpMake = fopen("_tmpMake","w");
   fprintf(tmpMake, "include $(DG_BUILD_DIR)/CMakeFiles/dg.dir/flags.make\n"
       "%s : %s\n"
       "\tg++ -fPIC -shared -o $@ $(CXX_FLAGS) $(CXX_DEFINES) $<\n",
-      filename.c_str(), "_tmpSrc.cpp");
+      libfilename.c_str(), cfilename.c_str());
   fclose(tmpMake);
   if(system("make -f _tmpMake"))
     Msg::Error("make command failed\n");
-  UnlinkFile("_tmpSrc.cpp");
   UnlinkFile("_tmpMake.cpp");
 }
+
+void functionC::buildLibrary(std::string code, std::string filename) 
+{
+  FILE *tmpSrc = fopen("_tmpSrc.cpp","w");
+  fprintf(tmpSrc, "%s\n",code.c_str());
+  fclose(tmpSrc);
+	buildLibraryFromFile("_tmpSrc.cpp", filename);
+  UnlinkFile("_tmpSrc.cpp");
+}
 void functionC::call (dataCacheMap *m, fullMatrix<double> &val) 
 {
   switch (args.size()) {
diff --git a/Solver/function.h b/Solver/function.h
index 73214942056053804bc319ff5501e478c770a2b8..d2946bc0290e4066465cc9d60581055f0a45135e 100644
--- a/Solver/function.h
+++ b/Solver/function.h
@@ -285,6 +285,7 @@ class functionC : public function {
   void (*callback)(void);
   public:
   static void buildLibrary(std::string code, std::string filename) ;
+	static void buildLibraryFromFile(const std::string cfilename, const std::string libfilename);
   void call (dataCacheMap *m, fullMatrix<double> &val) ;
   functionC (std::string file, std::string symbol, int nbCol, 
              std::vector<const function *> dependencies);