              while ((dirp = readdir(dp)) != NULL)
              {
                  if (dirp->d_type == DT_REG)
-@@ -89,6 +90,7 @@
+@@ -89,6 +90,7 @@ namespace cv
                  }
              }
              closedir(dp);

         #endif
 
         return list;
@@ -166,7 +168,8 @@
             {
                 return list;
             }

     #else
         #define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), (delta), 5)
     #endif
diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp
index 8899363..d18824a 100644
--- a/modules/core/src/system.cpp
+++ b/modules/core/src/system.cpp
@@ -460,7 +460,11 @@ string tempfile( const char* suffix )
     const int fd = mkstemp((char*)fname.c_str());
     if (fd == -1) return string();
 
+# ifndef __native_client__
     close(fd);
+# else
+    fclose((FILE*)fd);
+# endif  //#ifndef __native_client__
     remove(fname.c_str());
 # endif
 
diff --git a/modules/flann/include/opencv2/flann/allocator.h b/modules/flann/include/opencv2/flann/allocator.h
index 26091d0..5a77c50 100644
--- a/modules/flann/include/opencv2/flann/allocator.h
+++ b/modules/flann/include/opencv2/flann/allocator.h
@@ -68,7 +68,10 @@ T* allocate(size_t count = 1)
  *
  */
 
+// Some NaCl toolchains used to defined this.
+#if !defined(__native_client__) || !defined(WORDSIZE)
 const size_t     WORDSIZE=16;
+#endif
 const  size_t     BLOCKSIZE=8192;
 
 class PooledAllocator
diff --git a/modules/legacy/include/opencv2/legacy/legacy.hpp b/modules/legacy/include/opencv2/legacy/legacy.hpp
index 96da25c..cc0b4d3 100644
--- a/modules/legacy/include/opencv2/legacy/legacy.hpp
+++ b/modules/legacy/include/opencv2/legacy/legacy.hpp
@@ -519,8 +519,8 @@ typedef struct CvStereoCamera
 
     /* New part for stereo */
     CvPoint3D32f epipole[2];
