Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Attempting to get C code to find size of directory to compile with Emscripten

I'm having an issue getting my C code to compile with emscripten; fun fact this my first stack overflow post, as most of the time when I have an issue regarding a system or programming language there is a pre-existing question on here I can reference to get an answer, however this is different. I'm attempting to display the size of my Django Root directory on the webpage, this is the C code I am attempting to compile.

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <ftw.h>
#include <sys/types.h>
#include <sys/stat.h>

static unsigned int total = 0;

int sum(const char *fpath, const struct stat *sb, int typeflag)
{
    total += sb->st_size;
    return 0;
}

int main()
{
    char *DJANGO_ROOT = "/usr/src/app";
    if (!DJANGO_ROOT || access(DJANGO_ROOT, R_OK))
    {
        return 1;
    }
    if (ftw(DJANGO_ROOT, &sum, 1))
    {
        perror("ftw");
        return 2;
    }
    printf("%s: %u\n", DJANGO_ROOT, total);
    return 0;
}

This is the output I receive when attempting to compile the file using "emcc dir_size.c -o dir_size.html"

yalt@mainframe:~/Network/Mainframe/rabbithole_site/django_root/my_app/static/js/wasm/dir_size$ emcc dir_size.c -o dir_size.html
error: undefined symbol: ftw (referenced by top-level compiled C/C++ code)
warning: Link with `-sLLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _ftw may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '/home/yalt/emsdk/node/14.18.2_64bit/bin/node /home/yalt/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpwyeoj1vu.json' failed (returned 1)
yalt@mainframe:~/Network/Mainframe/rabbithole_site/django_root/my_app/static/js/wasm/dir_size$

It appears to me that emcc is having some difficulty recognizing the file tree walk (ftw) function; however I am unsure how to properly pass the function to the compiler, as I am very new to Emscripten and webassembly in general.

Any help/tips would be greatly appreciated!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The proximate issue is that the ftw function is not included in emscripten's libc.

However, even if it was included, or re-implemented, the program probably won't do what you want it to. /usr/src/app sounds like a directory that exists on the server, but WebAssembly code generally runs on the client and uses its own filesystem layer, normally an in-memory file system, so you won't be able to access the server filesystem at all.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!