adamgreen / gcc4mbed

Project to allow GCC compilation of code using mbed SDK libraries.
172 stars 68 forks source link

mbedUpdate #66

Closed iamshengluchen closed 6 years ago

iamshengluchen commented 6 years ago

when I make the 'mbedUpdate',there occur an error; "main.cpp:2377:73: error: ‘struct dirent’ has no member named ‘d_namWhat '" What should I do to solve this problem?

adamgreen commented 6 years ago

"main.cpp:2377:73: error: ‘struct dirent’ has no member named ‘d_namWhat '"

d_namWhat isn't an identifier that I see on line 2377. Was the error actually about d_name? What environment (operating system, compiler, etc) are you performing this build on? I have only tested it on macOS with the Xcode command line tools. I would expect it to work on other Posix systems like Linux but I don't know about Windows.

iamshengluchen commented 6 years ago

sorry, it is ”d_namLen“, My OS is Ubuntu 16.04 and the version of gcc is 5.4.0. the error is "main.cpp:2377:73: error: ‘struct dirent’ has no member named ‘d_namlen’ pChildPath = (char*)malloc(fullBaseLength + 1 + pEntry->d_namlen + "

adamgreen commented 6 years ago

I see. You could try applying this diff and it might help with that particular problem.

--- a/mbedUpdater/main.cpp
+++ b/mbedUpdater/main.cpp
@@ -2369,6 +2369,7 @@ static bool recurseMbedDirectories(FILE* pFile, const char* pFullDirName, const
     struct dirent* pEntry = NULL;
     while (NULL != (pEntry = readdir(pDir)))
     {
+        size_t nameLength = strlen(pEntry->d_name);
         switch (pEntry->d_type)
         {
         case DT_DIR:
@@ -2376,7 +2377,7 @@ static bool recurseMbedDirectories(FILE* pFile, const char* pFullDirName, const
                 0 != strcmp(pEntry->d_name, "..") && 
                 0 != strcmp(pEntry->d_name, ".git"))
             {
-                pChildPath = (char*)malloc(fullBaseLength + 1 + pEntry->d_namlen + 1);
+                pChildPath = (char*)malloc(fullBaseLength + 1 + nameLength + 1);
                 if (!pChildPath)
                 {
                     fprintf(stderr, "error: Failed to allocate memory for %s/%s\n", pFullDirName, pEntry->d_name);
@@ -2384,7 +2385,7 @@ static bool recurseMbedDirectories(FILE* pFile, const char* pFullDirName, const
                 }
                 sprintf(pChildPath, "%s/%s", pFullDirName, pEntry->d_name);

-                pRelativePath = (char*)malloc(relativeBaseLength + 1 + pEntry->d_namlen + 1);
+                pRelativePath = (char*)malloc(relativeBaseLength + 1 + nameLength + 1);
                 if (!pRelativePath)
                 {
                     fprintf(stderr, "error: Failed to allocate memory for %s/%s\n", pRelativeDirName, pEntry->d_name);
@@ -2405,7 +2406,7 @@ static bool recurseMbedDirectories(FILE* pFile, const char* pFullDirName, const
         case DT_REG:
             if (0 == strcmp(pEntry->d_name, ".mbedignore"))
             {
-                pChildPath = (char*)malloc(fullBaseLength + 1 + pEntry->d_namlen + 1);
+                pChildPath = (char*)malloc(fullBaseLength + 1 + nameLength + 1);
                 if (!pChildPath)
                 {
                     fprintf(stderr, "error: Failed to allocate memory for %s/%s\n", pFullDirName, pEntry->d_name);
iamshengluchen commented 6 years ago

Thank you very much. The code work successfully.

adamgreen commented 6 years ago

Cool. I will commit that change during my next push, no ETA on that though.