Struggling to compile my C code with emscripten for the first time. Usually, I find solutions on Stack Overflow, but this time is different. I'm trying to show the size of my Django Root directory on a webpage with the following C code:
#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;
}
When I try to compile the file using "emcc dir_size.c -o dir_size.html", I get the following error:
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 seems like emcc is having trouble recognizing the ftw function. As a newbie to Emscripten and webassembly, I'm not sure how to properly pass the function to the compiler. Any advice or assistance would be much appreciated!