Prebuild fbc+emscripten installer

Emscripten, WASM, and asm.js related questions
Post Reply
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Prebuild fbc+emscripten installer

Post by linuxanddos »

Hello fb community,

I'm trying to build the fbc+emscripten compiler to build some programs and play around.
But the guide from https://freebasic.net/wiki/devbuildemscripten seems to be very extensive and complicated and seems to link to https://freebasic.net/wiki/DevBuildWindows which has even more tools and folders to manage.

Also, I'm not sure if this guild isn't outdated now.

So I want to ask if there are any prebuild version of the fbc+emscripten compiler - or if it would be possible for you to provide a script (or even a program written in FreeBasic) than automates all the downloading, unpacking, compiling etc. until you can run the command to compile your own programs.

I have a Linux and a Windows computer to try this.

Best Regards,

linuxanddos
angros47
Posts: 2329
Joined: Jun 21, 2005 19:04

Re: Prebuild fbc+emscripten installer

Post by angros47 »

Basically, you need FreeBasic for your system, and its source code. Then, you need to install Emscripten: under Linux, the procedure is something like:

Code: Select all

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
As described here: https://emscripten.org/docs/getting_sta ... loads.html

At this point, you need to compile the runtime libraries for Emscripten, you do it with:

Code: Select all

make rtlib gfxlib2 TARGET=asmjs-unknown-emscripten ENABLE_STANDALONE=1
You might have to manually copy the files :termlib_min.js , fb_shell.html , fb_rtlib.js , fbextra.x in the lib directory and in the lib/freebasic/js-asmjs directory

At this point, it should be able to work
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Thanks. Now it is almost working (on Linux).

But if I try to compile, there is the following error:

Code: Select all

wasm-ld: error: unable to find library -lfb
wasm-ld: error: unable to find library -lfbgfx
wasm-ld: error: unable to find library -lfb
I think I've missed some environment variable, but sadly, I don't know which one.

EDIT: It seems like I do not have an /lib/freebasic directory.
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

I have found the folder: /usr/local/lib/freebasic/
Now it is compiling, but it seems like I have to enable async support...
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Now my software is almost working.

But I need some conditional compiling distinguishing between emscripten and the other platforms.
Is there something like

Code: Select all

#ifdef __FB_DOS__ 
	'code here
#endif
for emscripten/wasm?
coderJeff
Site Admin
Posts: 4345
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Prebuild fbc+emscripten installer

Post by coderJeff »

There is a builtin define, available since emscripten target was added to fbc:

Code: Select all

'' defined for '-target js-asmjs'
#ifdef __FB_JS__
#endif
Not in the wiki / manual, but should probably be added (even if exact naming changes in future).
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Prebuild fbc+emscripten installer

Post by fxm »

New page added:
KeyPgDdfbjs → fxm [new page '__fb_js__']
and also all the induced links.
linuxanddos
Posts: 19
Joined: Oct 28, 2023 13:31

Re: Prebuild fbc+emscripten installer

Post by linuxanddos »

Somewhere in this forum I have read that it is possible to run JS code from your FreeBasic app. Sadly, I don't find this message again.

Instead, I found this: https://emscripten.org/docs/porting/con ... rom-native

How can I use this in FreeBasic?
Post Reply