1

I tried compiler TCC(Tiny C compiler: https://bellard.org/tcc/) form source code:

$ pwd
/cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27

Administrator@MS-QMYKYRDOTLFI /cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27
$ ./configure
Binary directory    C:/Program Files/tcc
TinyCC directory    C:/Program Files/tcc
Library directory   C:/Program Files/tcc/libtcc
Doc directory       C:/Program Files/tcc/doc
Source path         .
C compiler          gcc (11.2)
Target OS           CYGWIN_NT-10.0
CPU                 x86_64
Config              WIN32
Creating config.mak and config.h
config.h is unchanged

after configutre, make, make install.

then, i run the fib.c, it show error message:

$ pwd
/cygdrive/c/Program Files/tcc/examples

Administrator@MS-QMYKYRDOTLFI /cygdrive/c/Program Files/tcc/examples
$ ../tcc.exe  -run fib.c 12
tcc: error: -run is not available in a cross compiler

This is run on Windows 10, Cygwin64 Terminal.

I check the source code, in libtcc.c, there are these lines:

#ifndef TCC_IS_NATIVE
            tcc_error("-run is not available in a cross compiler");
#endif

Maybem the reason is, when i "make", i didnot add _DTCC_IS_NATIVE? I don't know.

If i download tcc-0.9.27-win64-bin form web, '-run' works! Please help me , how to generate a tcc.exe can use '-run'.

Thanks!

Add CPPFLAGS or CFLAGS , also did not work:

$ ./configure CPPFLAGS="-DTCC_IS_NATIVE"
configure: WARNING: unrecognized option CPPFLAGS=-DTCC_IS_NATIVE
Binary directory    C:/Program Files/tcc
TinyCC directory    C:/Program Files/tcc
Library directory   C:/Program Files/tcc/libtcc
Doc directory       C:/Program Files/tcc/doc
Source path         .
C compiler          gcc (11.2)
Target OS           CYGWIN_NT-10.0
CPU                 x86_64
Config              WIN32
Creating config.mak and config.h
config.h is unchanged

Put CPPFLAGS before configure, also did not work:

Administrator@MS-QMYKYRDOTLFI /cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27
$ CPPFLAGS=-DTCC_IS_NATIVE ./configure
Binary directory    C:/Program Files/tcc
TinyCC directory    C:/Program Files/tcc
Library directory   C:/Program Files/tcc/libtcc
Doc directory       C:/Program Files/tcc/doc
Source path         .
C compiler          gcc (11.2)
Target OS           CYGWIN_NT-10.0
CPU                 x86_64
Config              WIN32
Creating config.mak and config.h
config.h is unchanged

$ make
gcc -o tcc.o -c tcc.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o libtcc.o -c libtcc.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccpp.o -c tccpp.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccgen.o -c tccgen.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccelf.o -c tccelf.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccasm.o -c tccasm.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccrun.o -c tccrun.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o x86_64-gen.o -c x86_64-gen.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o x86_64-link.o -c x86_64-link.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o i386-asm.o -c i386-asm.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
gcc -o tccpe.o -c tccpe.c -DTCC_TARGET_X86_64 -DTCC_TARGET_PE       -DLIBTCC_AS_DLL -DONE_SOURCE=0 -Wall -g -O2 -Wdeclaration-after-statement -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -I.
In function ‘pe_write’,
    inlined from ‘pe_output_file’ at tccpe.c:1975:19:
tccpe.c:677:9: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation]
  677 |         strncpy((char*)psh->Name, sh_name, sizeof psh->Name);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -shared -o libtcc.dll libtcc.o tccpp.o tccgen.o tccelf.o tccasm.o tccrun.o x86_64-gen.o x86_64-link.o i386-asm.o tccpe.o -static
gcc -o tcc.exe tcc.o libtcc.dll  -static
make[1]: Entering directory '/cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27/lib'
../tcc.exe -c libtcc1.c -o libtcc1.o -B../win32 -I../include
../tcc.exe -c alloca86_64.S -o alloca86_64.o -B../win32 -I../include
../tcc.exe -c alloca86_64-bt.S -o alloca86_64-bt.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/chkstk.S -o chkstk.o -B../win32 -I../include
../tcc.exe -c bcheck.c -o bcheck.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/crt1.c -o crt1.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/crt1w.c -o crt1w.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/wincrt1.c -o wincrt1.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/wincrt1w.c -o wincrt1w.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/dllcrt1.c -o dllcrt1.o -B../win32 -I../include
../tcc.exe -c ../win32/lib/dllmain.c -o dllmain.o -B../win32 -I../include
../tcc.exe -ar rcs ../libtcc1.a libtcc1.o alloca86_64.o alloca86_64-bt.o chkstk.o bcheck.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
make[1]: Leaving directory '/cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27/lib'
./tcc.exe -impdef libtcc.dll -o libtcc.def
makeinfo tcc-doc.texi || true
Can't locate Texinfo/ModulePath.pm in @INC (you may need to install the Texinfo::ModulePath module) (@INC contains: /mingw64/share/texinfo /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.32 /usr/lib/perl5/vendor_perl/5.32/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.32 /usr/lib/perl5/5.32/x86_64-cygwin-threads /usr/share/perl5/5.32) at /cygdrive/d/Program Files/GNU Octave/Octave-6.3.0/mingw64/bin/makeinfo line 82.
BEGIN failed--compilation aborted at /cygdrive/d/Program Files/GNU Octave/Octave-6.3.0/mingw64/bin/makeinfo line 85.


$ make install
mkdir -p "C:/Program Files/tcc" && install -m755  tcc.exe libtcc.dll "C:/Program Files/tcc"
mkdir -p "C:/Program Files/tcc/lib" && install -m644 ./win32/lib/*.def "C:/Program Files/tcc/lib"
mkdir -p "C:/Program Files/tcc/lib" && install -m644 libtcc1.a "C:/Program Files/tcc/lib"
mkdir -p "C:/Program Files/tcc/include" && install -m644 ./include/*.h ./tcclib.h "C:/Program Files/tcc/include"
mkdir -p "C:/Program Files/tcc/include" && cp -r ./win32/include/. "C:/Program Files/tcc/include"
mkdir -p "C:/Program Files/tcc/examples" && cp -r ./win32/examples/. "C:/Program Files/tcc/examples"
mkdir -p "C:/Program Files/tcc/examples" && install -m644 ./tests/libtcc_test.c "C:/Program Files/tcc/examples"
mkdir -p "C:/Program Files/tcc/libtcc" && install -m644 ./libtcc.h libtcc.def "C:/Program Files/tcc/libtcc"
mkdir -p "C:/Program Files/tcc/doc" && install -m644 ./win32/tcc-win32.txt tcc-doc.html "C:/Program Files/tcc/doc"

Administrator@MS-QMYKYRDOTLFI /cygdrive/D/Download/tcc-0.9.27/tcc-0.9.27
$ cd -
/cygdrive/c/Program Files/tcc/examples

Administrator@MS-QMYKYRDOTLFI /cygdrive/c/Program Files/tcc/examples
$ pwd
/cygdrive/c/Program Files/tcc/examples

Administrator@MS-QMYKYRDOTLFI /cygdrive/c/Program Files/tcc/examples
$ ../tcc.exe -run fib.c 12
tcc: error: -run is not available in a cross compiler
zhaoyun
  • 11
  • 4
  • Did you try to build TCC with `TCC_IS_NATIVE`? – the busybee Mar 17 '22 at 16:17
  • No , I don't how to do that... – zhaoyun Mar 17 '22 at 16:19
  • 1
    Well, currently I'm not able to look it up, but you should do it yourself anyway: Search how to provide such a definition to the call of "configure". I'm sure it is quite simple. -- BTW, TCC's documentation says that it support only 32 bit Windows... This can be another reason. – the busybee Mar 17 '22 at 16:24
  • Put `CPPFLAGS=-DTCC_IS_NATIVE` _before_ `./configure` so it's passed as an environment variable rather than a command-line argument. Putting it after works for GNU autoconf versions of `configure`, but this presumably isn't one of those. – Charles Duffy Mar 17 '22 at 17:13

1 Answers1

0

You just need to clone this repository https://repo.or.cz/tinycc.git.

And you need to configure the build to compile to i386.

You run the command ./configure --cpu=i386 and then make.

That's it, then you have to install it with make install.