6

Can I use a socket library from TCC? I can't find any reference to winsock or sys/socket.h in the include directory.

If i remember correctly, winsock was part of the windows platform SDK (?) If so can I link that with TCC?

3 Answers3

9

According to Tinycc-devel mailing list

you should give this a try:

tiny_impdef winsock.dll -o winsock.def
tcc yourcode.c  winsock.def -o yourcode.exe
stacker
  • 68,052
  • 28
  • 140
  • 210
  • Found wsock32.h on google code search. It included a few others that were easily found. Worked like a charm, cheers –  Nov 01 '10 at 16:23
  • @tm1rbrt how do you know it worked like a charm if you got the file from somewhere rather than use the method in the answer? btw tcc asks for winsock.h maybe renaming wsock32.h to winsock.h works If so you could put that in your own answer. And it requires common.h which isn't in there. – barlop May 07 '14 at 17:37
8
  1. Use tiny_impdef.exe to export definitions from the DLL file using the command line:
    tiny_impdef.exe wsock32.dll -o .\lib\wsock32.def

  2. You will also need the header files for your source code to include them. MinGW's ones (such as winsock2.h, ws2tcpip.h, ws2spi.h...) can be reused with TCC.
    The MinGW compiler can be downloaded from here. Just copy the headers you need from MinGW's include directory to TCC's include\winapi directory.

  3. At compilation time, you will need to tell the compiler you are using the Windows socket library:
    tcc.exe path\to\code.c -lwsock32 -o path\to\program.exe

Mathieu Rodic
  • 6,637
  • 2
  • 43
  • 49
  • C:\Users\compile\Desktop\tcc>tcc.exe code.c -lwsock32 -o program.exe In file included from code.c:6: c:/users/compile/desktop/tcc/include/winapi/winsock2.h:10: error: include file '_mingw_unicode.h' not found – user3789797 Sep 01 '20 at 08:54
  • Used mingw-w64-v7.0.0: https://sourceforge.net/projects/mingw-w64/ And tcc-0.9.27-win64-bin.zip http://download.savannah.gnu.org/releases/tinycc/ – user3789797 Sep 01 '20 at 08:57
  • mingw-w64-v7.0.0.zip\mingw-w64-headers\crt folder does contain _mingw_unicode.h – user3789797 Sep 01 '20 at 08:59
  • However dropping all the headers from mingw-w64-v7.0.0.zip\mingw-w64-headers\crt to the tcc\include does not resolve the problem and continually shows different error: – user3789797 Sep 01 '20 at 09:02
  • C:\Users\compile\Desktop\tcc>tcc.exe code.c -lwsock32 -o program.exe In file included from code.c:5: In file included from c:/users/compile/desktop/tcc/include/stdio.h:9: In file included from c:/users/compile/desktop/tcc/include/crtdefs.h:10: In file included from c:/users/compile/desktop/tcc/include/corecrt.h:10: In file included from c:/users/compile/desktop/tcc/include/_mingw.h:27: c:/users/compile/desktop/tcc/include/stddef.h:18: error: ';' expected (got "extern") – user3789797 Sep 01 '20 at 09:02
  • It seems that latest TCC compiler compiled from git repository sources code does work properly with winsocks and some other libraries. – user3789797 Sep 25 '20 at 06:44
  • Sorry, I haven't used TCC nor used Windows since 2013... – Mathieu Rodic Sep 25 '20 at 14:26
1
tiny_impdef winsock.dll 

copy winsock.def to lib/

run:

tcc -lwinsock yourcode.c -o yourcode.exe