Could I use fbc -gen gcc with clang as the compiler?

New to FreeBASIC? Post your questions here.
srvaldez
Posts: 2483
Joined: Sep 25, 2005 21:54

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby srvaldez » May 04, 2020 16:19

I made 2 batch files to make easier to play with
goclang32.bat

Code: Select all

C:\msys64\mingw32\bin\fbc -gen gcc -arch 32 -asm att -r -m %~n1 %1
C:\msys64\mingw32\bin\clang -Ofast %~n1.c -c -o %~n1.o
C:\msys64\mingw32\bin\fbc -arch native %~n1.o

goclang64.bat

Code: Select all

C:\msys64\mingw64\bin\fbc -gen gcc -arch 64 -asm att -r -m %~n1 %1
C:\msys64\mingw64\bin\clang -Ofast %~n1.c -c -o %~n1.o
C:\msys64\mingw64\bin\fbc -arch native %~n1.o

I use geany for my editor, the compile command is: "goclang32.bat" "%f"
srvaldez
Posts: 2483
Joined: Sep 25, 2005 21:54

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby srvaldez » May 04, 2020 20:32

for anyone interested here are the msys2 clang executables, it includes batch files to make it easy to try, I suggest that you place the batch files on the desktop and edit them to correct the paths for your system
then you can simply drag-&-drop a bas file on top of the batch file to create a clang executable
the name of the bas file must not contain spaces
in my test ShawnLG worm hole viewtopic.php?p=271384#p271384 the 32-bit version was much faster than the 64-bit
clang32
clang64
srvaldez
Posts: 2483
Joined: Sep 25, 2005 21:54

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby srvaldez » May 04, 2020 22:47

fixed the batch files to accept spaces
32-bit

Code: Select all

D:\dev\FreeBASIC-1.08.0-win32-gcc-10\fbc -gen gcc -arch 32 -asm att -r -m "%~n1" %1
C:\Users\Admin\Desktop\clang32\bin\clang.exe -Ofast "%~n1.c" -c -o "%~n1.o"
D:\dev\FreeBASIC-1.08.0-win32-gcc-10\fbc -arch native "%~n1.o"
del "%~n1.o"
del "%~n1.c"

64-bit

Code: Select all

D:\dev\FreeBASIC-1.08.0-win64-gcc-10\fbc -gen gcc -arch 64 -asm att -r -m "%~n1" %1
C:\Users\Admin\Desktop\clang64\bin\clang.exe -Ofast "%~n1.c" -c -o "%~n1.o"
D:\dev\FreeBASIC-1.08.0-win64-gcc-10\fbc -arch native "%~n1.o"
del "%~n1.o"
del "%~n1.c"
srvaldez
Posts: 2483
Joined: Sep 25, 2005 21:54

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby srvaldez » May 05, 2020 0:51

tricky batch files :LOL:
didn't know this was possible with batch files, try to guess what the following batch file does

Code: Select all

D:\dev\FreeBASIC-1.08.0-win%3-gcc-10\fbc -gen gcc %2 %3 -asm att -r -m "%~n1" %1
C:\Users\Admin\Desktop\clang%3\bin\clang.exe %4 "%~n1.c" -c -o "%~n1.o"
D:\dev\FreeBASIC-1.08.0-win%3-gcc-10\fbc -arch native "%~n1.o"
del "%~n1.o"
del "%~n1.c"

using geany I have the compile command: C:\Users\Admin\Desktop\goclang32.bat "%f" -arch 32 -Ofast
with the file name as "wormhole tunnel7.bas" the batch file translates it to:

Code: Select all

D:\dev\FreeBASIC-1.08.0-win32-gcc-10\fbc -gen gcc -arch 32 -asm att -r -m "wormhole tunnel7" "wormhole tunnel7.bas"
C:\Users\Admin\Desktop\clang32\bin\clang.exe -Ofast "wormhole tunnel7.c" -c -o "wormhole tunnel7.o"
D:\dev\FreeBASIC-1.08.0-win32-gcc-10\fbc -arch native "wormhole tunnel7.o"

to compile to 64-bit I simply pass 64 instead of 32 in the compile command, so now I need to rename the batch file to something other than goclang32.bat
TeeEmCee
Posts: 298
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby TeeEmCee » May 05, 2020 13:45

BTW, pass -Wno-builtin-requires-header -Wno-incompatible-library-redeclaration to clang to silence the warnings about fbc-generated code.

srvaldez wrote:the command was fbc -gen gcc -arch 32 -asm att -r -m hello hello.bas
without the -asm att clang spits out error messages like: hello.c:71:3: error: ambiguous instructions require an explicit suffix (could be 'flds', 'fldl', or 'fldt')

Oh, I forgot that on x86 fbc -gen gcc outputs at least one function containing an asm block (for double to int conversion with FB instead of C semantics). Good to know, thanks. I can't test that here since I don't have a 32-bit-capable installation of clang on any OS.
systemctl
Posts: 182
Joined: Mar 27, 2020 5:15

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby systemctl » May 05, 2020 17:43

TeeEmCee wrote:BTW, pass -Wno-builtin-requires-header -Wno-incompatible-library-redeclaration to clang to silence the warnings about fbc-generated code.

srvaldez wrote:the command was fbc -gen gcc -arch 32 -asm att -r -m hello hello.bas
without the -asm att clang spits out error messages like: hello.c:71:3: error: ambiguous instructions require an explicit suffix (could be 'flds', 'fldl', or 'fldt')

Oh, I forgot that on x86 fbc -gen gcc outputs at least one function containing an asm block (for double to int conversion with FB instead of C semantics). Good to know, thanks. I can't test that here since I don't have a 32-bit-capable installation of clang on any OS.


clang is already a cross compiler. check with clang -v to see apart from m64 it also supports m32. If so, use clang -m32.

My clang on Debian x64 didn't output any error when compiling hello.c generated by fbc from hello.bas. So I don't know why you got these errors.
TeeEmCee
Posts: 298
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Could I use fbc -gen gcc with clang as the compiler?

Postby TeeEmCee » May 06, 2020 15:16

systemctl wrote:clang is already a cross compiler. check with clang -v to see apart from m64 it also supports m32. If so, use clang -m32.

You're right. (Thanks for the hint, I was confused by some other error message that I mistook to mean clang wasn't doing a 32-bit build. I fixed that problem.) But still, the clang on my multilib Slackware box can't find the libraries/etc to do a 32-bit build, although I have a multilib gcc. I haven't managed to figure out why.

Silly me, I forgot that my FreeBSD install in a VM can compile 32-bit binaries using either gcc or clang, I just hadn't compiled 32-bit rtlib/gfxlib2. It works after adding -asm att.
Interestingly though, "clang -v" there doesn't display any info about multilib/available targets or sysroots.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests