Striving to enable C code to determine the directory size for optimization with Emscripten compilation

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!

Answer №1

The main issue here is that the ftw function is missing from emscripten's libc.

Even if it were present or replaced, chances are high that the program will not perform as desired. /usr/src/app appears to be a valid server directory, but WebAssembly typically operates on the client side with its own filesystem layer, often an in-memory file system, limiting access to the server filesystem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide on converting nested arrays of objects in JavaScript

I am faced with transforming an array of Objects that contain a nested structure. Here is an example of the data: [ { geography: 'Austia', product: 'RTD Coffee', dataType: 'Off-Trade rsp (curr/con, lo ...

Custom JavaScript code in Bootstrap Navbar Toggler results in closing the menu when a dropdown is clicked

As a newcomer to JavaScript, I am currently learning the language while working on a website. I have customized a template that I found online but am struggling with the JS code that I'm not very familiar with. Here's my issue: When using the na ...

Adjust the size of each link in the highchart network diagram

Is it feasible to individually set the length of each link in a network graph using highcharts? I am interested in creating a visualization where each user is displayed at varying distances from the main center user. I have been experimenting with the lin ...

Provide input data to the function for delivery purposes

Creating a simple webpage with a form input that triggers a script to request JSON data from the server based on the user's input. The challenge is passing the value from the input field to a function for processing. var search = document.querySele ...

JQuery syntax for adding a comma before the first element in an array

When I insert data into an array, the output in my console includes a comma before the first element (9). How can I remove this comma from the first element using the provided code snippet? ,9,My firstname,My lastname,<a href="/cdn-cgi/l/email-protecti ...

optimal method for displaying HTML strings with components in Vue

My website is a Blog/News site featuring posts that contain HTML content stored in the database. In addition to posts, I also want to include elements like sliders which cannot be generated using v-html. I explored Vue's Render Functions to find a so ...

Angular routes cause a glitch in the Bootstrap navbar, causing it to shift to the left on certain active

Apologies for the simple question, I am new to web design and couldn't find a solution even after extensive googling and searching. The issue I am facing is that when clicking on "EX5" or "EX6" in my navbar, it shifts to the left side of the screen i ...

JavaScript code to find a date within a specified range

I have developed a script that calculates the number of weeks between two specified dates. It then generates a table where the number of rows equals the number of weeks. The script can be viewed on JSFIDDLE Script: $('#test').click(function ...

ES6: Using DataURI to provide input results in undefined output

In my current project, I am facing a challenge. I am attempting to pass image dataURI as an input from a url link to the image. To achieve this task, I know that I have to utilize canvas and convert it from there. However, since this process involves an &a ...

Vue.js - The @oninput.native listener does not trigger in b-form-textarea components

I have a Vue application and I am trying to incorporate Facebook inspired buttons inline in a comment form. Previously, I had a plain JavaScript prototype that was functional. However, when integrating it into my Vue app, I encountered issues due to multip ...

Do you have any recommendations for a jQuery plugin that can create a sleek horizontal scrolling image gallery?

Recently, I came across the Smooth div scroll plugin developed by Thomas Kahn, and it fits my requirements perfectly. However, I have encountered a bug that seems to be persisting. The issue arises when both mousewheel scroll and touch scroll are enabled s ...

The ExpressJS Req.method TypeError occurs when attempting to read the 'method' property of an undefined object

My node express server is throwing an error: Error in index.js. const bodyParser = require('body-parser'), express = require('express'), path = require('path'); const config = require('./config'); con ...

Unable to send a namespaced action from a different module: [vuex] action type is not recognized

In my coding project, I am working with two different modules called activities and alerts. One of the requirements is that whenever an activity is added, I need to trigger an alert action with the namespaced identifier alerts/SHOW. This functionality was ...

Being able to automatically update my JSON file without needing to manually refresh the webpage is a feature I am interested in exploring

I have a server that automatically updates a JSON file. However, the JavaScript code I have implemented below reads the JSON file and displays it to the client, but it always refreshes the page. I am looking for a solution on how to read my JSON file ever ...

The Python Django website is not displaying properly on Ubuntu as it does on Windows

Encountering an issue without knowing its origin is a common problem in web development. I have the same website running on Django 3.0.8 in two different environments - one on a Windows 10 PC and the other on an old Xubuntu 20.04 PC: Despite having identi ...

Setting a time delay in a RESTful service

I am currently working on a service built with node.js + express. However, I am facing issues with managing the timer functionality. My service does not maintain any state, and it consists of 2 functions in the route. route.js var timerId; exports.linkU ...

Storing JSON data using Vuex

As I am delving into the world of Vuex store used with vue.js, I find myself wanting to implement it in a specific scenario. 1. Is STATE referring to any data, whether static or dynamic, that is provided by the server or stored in a JSON format? TEMPLATE ...

Storing a function value in a variable within a Node.js server to retrieve folder size

I have been searching for a way to determine the size of a folder's contents and discovered that using the get-folder-size package is the best option. The code snippet below explains how to achieve this: const express = require('express'); ...

Tips for real-time content updates on a server-side rendered express application

My social media app, built using Express, Pug, and JavaScript for server-side rendering, is fully functional. However, whenever I comment on a post, I need to manually reload the page to see the new comment displayed. I'm exploring ways to dynamicall ...

Adding an item to a nested array within an object in a Redux reducer

Here is an example of my initial state: let initialState = { data: { name: 'john', books: [ { name: 'a', price: 220 } ] } } Is there ...