FreeBASIC + tcc

New to FreeBASIC? Post your questions here.
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

FreeBASIC + tcc

Postby ddress » Apr 06, 2020 2:18

Im thying to link with "C" code

Code: Select all

'------------------------------------------------------------------------
EXTERN "C"
Declare sub main_setup()
Declare sub main_loop()
END EXTERN
'------------------------------------------------------------------------
'' main
'------------------------------------------------------------------------
Function fbMain(byref URL as string) as uinteger

      main_setup()
      main_loop()
     
      return 0

end Function
'------------------------------------------------------------------------
fbMain(Command(1))
end

C code:

Code: Select all

/***************************************************************************/
void main_loop()
{
    int a=666;

}
/***********************************************************/
void main_setup()
{
    int a=666;
}
/***************************************************************************/
int main( int argc, char ** argv )
{
    int a=666;

    return 1;
}

best i get is:

Code: Select all

fbc.exe -lang fb -l TinyBasicPlus  TinyBasicBAS.bas                                                   
TinyBasicBAS.o:fake:(.text+0xe): undefined reference to `main_setup'                                                                                                     
TinyBasicBAS.o:fake:(.text+0x13): undefined reference to `main_loop'
marcov
Posts: 2945
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: FreeBASIC + tcc

Postby marcov » Apr 06, 2020 8:18

Look at the error I would guess FB generates a mangled name that starts with _, and tcc not?

IIRC ABI for (PE)COFF specifies a lead _ for C compilers.
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 08, 2020 21:59

marcov wrote:Look at the error I would guess FB generates a mangled name that starts with _, and tcc not?

IIRC ABI for (PE)COFF specifies a lead _ for C compilers.

like this?

Code: Select all

/***************************************************************************/
void _main_loop()
{
    int a=666;

}
/***********************************************************/
void _main_setup()
{
    int a=666;
}
/***************************************************************************/
int main( int argc, char ** argv )
{
    int a=666;

    return 1;
}
MrSwiss
Posts: 3455
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBASIC + tcc

Postby MrSwiss » Apr 08, 2020 22:07

I see another potential issue: different data-types ...
Integer/UInteger in FB are NOT the same as: int/unsigned int (aka: uint) in C!
The corresponding FB data-type is: Long/ULong (fixed size, 32 bit int-type)
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 09, 2020 13:01

ddress wrote:

Code: Select all

void _main_loop()
void _main_setup()


this gives error:

Code: Select all

fbc.exe -lang fb -l TinyBasicPlus TinyBasicBAS.bas
ld.exe: internal error ../../../src/binutils-2.25/ld/ldlang.c 6257
Last edited by ddress on Apr 09, 2020 13:09, edited 1 time in total.
marcov
Posts: 2945
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: FreeBASIC + tcc

Postby marcov » Apr 09, 2020 13:04

See if you can dump symbols in the tcc compiler with nm

nm -a x.o > symbollist.txt

and search for the symbols that you miss.

If both tcc and binutils have a nm, use the one from binutils
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 09, 2020 13:11

marcov wrote:See if you can dump symbols in the tcc compiler with nm

nm -a x.o > symbollist.txt

and search for the symbols that you miss.

If both tcc and binutils have a nm, use the one from binutils

i have only this

Code: Select all

01/27/2019  02:51         1,016,320 ar.exe
01/27/2019  08:57         1,730,048 as.exe
01/27/2019  08:57         1,046,016 dlltool.exe
01/27/2019  08:57         6,263,511 gdb.exe
01/27/2019  08:57            58,880 GoRC.exe
01/27/2019  08:57         1,057,792 gprof.exe
01/27/2019  08:57         1,391,104 ld.exe
MrSwiss
Posts: 3455
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBASIC + tcc

Postby MrSwiss » Apr 09, 2020 13:29

ddress wrote:i have only this

Those are the FB bin-tools; marcov has clearly asked for the TCC stuff.
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 09, 2020 13:38

marcov wrote:See if you can dump symbols in the tcc compiler with nm

nm -a x.o > symbollist.txt

and search for the symbols that you miss.

If both tcc and binutils have a nm, use the one from binutils


Code: Select all

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x0000000000000000 0xffffffffffffffff

Linker script and memory map

                0x0000000000400000                __image_base__ = 0x400000
                0x0000000000000000                __dll__ = 0x0
                0x0000000000400000                ___ImageBase = 0x400000
                0x0000000000001000                __section_alignment__ = 0x1000
                0x0000000000000200                __file_alignment__ = 0x200
                0x0000000000000004                __major_os_version__ = 0x4
                0x0000000000000000                __minor_os_version__ = 0x0
                0x0000000000000001                __major_image_version__ = 0x1
                0x0000000000000000                __minor_image_version__ = 0x0
                0x0000000000000004                __major_subsystem_version__ = 0x4
                0x0000000000000000                __minor_subsystem_version__ = 0x0
                0x0000000000000003                __subsystem__ = 0x3
                0x0000000000200000                __size_of_stack_reserve__ = 0x200000
                0x0000000000001000                __size_of_stack_commit__ = 0x1000
                0x0000000000100000                __size_of_heap_reserve__ = 0x100000
                0x0000000000001000                __size_of_heap_commit__ = 0x1000
                0x0000000000000000                __loader_flags__ = 0x0
                0x0000000000000000                __dll_characteristics__ = 0x0
LOAD TinyBasicPlus.o
                0x00000000000001f0                . = SIZEOF_HEADERS
                0x0000000000001000                . = ALIGN (__section_alignment__)

.text           0x0000000000401000      0x200
 *(.init)
 *(.text)
 .text          0x0000000000401000       0x5d TinyBasicPlus.o
                0x0000000000401000                main_loop
                0x0000000000401022                main_setup
                0x0000000000401044                main
MrSwiss
Posts: 3455
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBASIC + tcc

Postby MrSwiss » Apr 09, 2020 13:59

Now, I'm lost ...
What has *TinyBasicPlus to do with FB and/or TCC?

Could you please state in words, what you are really after?
What do you want to achieve? Which HW, as detailed as possible ...

*TinyBasicPlus seems to be for Arduino???
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 09, 2020 15:02

best i get is:

Code: Select all

fbc.exe -lang fb -l TinyBasicPlus TinyBasicBAS.bas
ld.exe: internal error ../../../src/binutils-2.25/ld/ldlang.c 6257
dodicat
Posts: 6390
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBASIC + tcc

Postby dodicat » Apr 09, 2020 16:18

the C file test.c

Code: Select all

/***************************************************************************/
int _main_loop()
{
    int a=666;
    return a;

}
/***********************************************************/
int _main_setup()
{
    int a=666;
    return a-66;
}
/***************************************************************************/
int main( int argc, char ** argv )
{
 
    return 0;

}


compile with tcc
tcc -c test.c to get test.o

Running nm on the object file (only to look at the table of functions)

nm test.o
result:

Code: Select all

00000000 T _main_loop
00000014 T _main_setup
00000028 T main 


The tester file for freebasic

Code: Select all


Declare function main_setup cdecl alias "main_setup"() as long
Declare function main_loop cdecl alias "main_loop"() as long


'------------------------------------------------------------------------
Function fbMain(byref URL as string) as uinteger
     print  main_loop()
     print  main_setup()
      return 0

end Function
'------------------------------------------------------------------------
fbMain(Command(1))
sleep
end


And using fbc test.o tester.bas
My result:

666
600
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 10, 2020 1:11

dodicat wrote:the C file test.c

Code: Select all

/***************************************************************************/
int _main_loop()
{
    int a=666;
    return a;

}
/***********************************************************/
int _main_setup()
{
    int a=666;
    return a-66;
}
/***************************************************************************/
int main( int argc, char ** argv )
{
 
    return 0;

}


compile with tcc
tcc -c test.c to get test.o

Running nm on the object file (only to look at the table of functions)

nm test.o
result:

Code: Select all

00000000 T _main_loop
00000014 T _main_setup
00000028 T main 


The tester file for freebasic

Code: Select all


Declare function main_setup cdecl alias "main_setup"() as long
Declare function main_loop cdecl alias "main_loop"() as long


'------------------------------------------------------------------------
Function fbMain(byref URL as string) as uinteger
     print  main_loop()
     print  main_setup()
      return 0

end Function
'------------------------------------------------------------------------
fbMain(Command(1))
sleep
end


And using fbc test.o tester.bas
My result:

666
600


best i get this way:

Code: Select all

TinyBasicPlus.o: In function `main_loop':
TinyBasicPlus.c:(.text+0x19): undefined reference to `printf'
TinyBasicPlus.o: In function `main_setup':
TinyBasicPlus.c:(.text+0x3b): undefined reference to `printf'
caseih
Posts: 1495
Joined: Feb 26, 2007 5:32

Re: FreeBASIC + tcc

Postby caseih » Apr 10, 2020 4:17

I wonder if your tcc is incompatible with the C runtime that your Fb installation uses by default. On Windows there are numerous versions of the C standard library in common use (depends on which version of the Mingw toolchain), and mixing them is always problematic. MS is trying to nudge everyone in the direct of the universal C runtime dll.

Of course if you don't use anything from the C runtime library in your C files, there will be no problems linking TCC object files with FB code.

I'm not sure if dodicat was using linux, but the default there, even for TCC, is glibc.
ddress
Posts: 12
Joined: Mar 12, 2020 18:50

Re: FreeBASIC + tcc

Postby ddress » Apr 10, 2020 5:58

caseih wrote:I wonder if your tcc is incompatible with the C runtime that your Fb installation uses by default. On Windows there are numerous versions of the C standard library in common use (depends on which version of the Mingw toolchain), and mixing them is always problematic. MS is trying to nudge everyone in the direct of the universal C runtime dll.

Of course if you don't use anything from the C runtime library in your C files, there will be no problems linking TCC object files with FB code.

I'm not sure if dodicat was using linux, but the default there, even for TCC, is glibc.

i use TCC for windows

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 5 guests