[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] libtcc.dll

From: Doug Currie
Subject: [Tinycc-devel] libtcc.dll
Date: Tue, 28 Feb 2006 22:41:27 -0500

I have been able to create a libtcc.dll for WinXP using MinGW/MSYS;
the changes that were necessary were very minor. Perhaps this
description will help others use libtcc on Windows.

First, a small bug to report:

In tcc.c the function tcc_basename() follows the line:

#if !defined(LIBTCC)

but the function tcc_basename() is used in pe_build_exports() in
tccpe.c -- moving the #if line below the function tcc_basename()
eliminates a link error building libtcc.dll in PE target mode.

Second, configuring and making tcc with MSYS places a pathname in
config.h in MSYS format. For example, I passed the argument


to configure; this path was good for building tcc.exe and didn't
contain any spaces, unlike the default path. This creates the line

#define CONFIG_TCCDIR "/c/Dev/tcc"

in config.h. Manually changing this line to

#define CONFIG_TCCDIR "C:/Dev/tcc"

enables libtcc.dll to find the include files and libraries once the
library is built. [The application tcc.exe avoids this problem by
setting tcc_lib_path from the application's directory at startup. A
similar solution could be used for the library using DllMain.]

So, after configure, fix CONFIG_TCCDIR in config.h and make.

Finally, the library libtcc.dll can be built with the MSYS command:

gcc -O2 -shared -Wall -Wl,--export-all-symbols \
-mpreferred-stack-boundary=2 \
-march=i386 -falign-functions=0 -fno-strict-aliasing \
-DTCC_TARGET_PE -DLIBTCC -o libtcc.dll tcc.c

Below is a diff of tcc-0.9.23 tcc.c and the changes for LIBTCC with
TCC_TARGET_PE and DLL location of library files.



$ diff -u ../tcc-0.9.23-o/tcc.c tcc.c
--- ../tcc-0.9.23-o/tcc.c       Fri Jun 17 18:09:15 2005
+++ tcc.c       Tue Feb 28 17:03:44 2006
@@ -10157,8 +10157,6 @@
                     flag_name, value);
-#if !defined(LIBTCC)
 /* extract the basename of a file */
 static const char *tcc_basename(const char *name)
@@ -10175,6 +10173,35 @@
     return p;
+#if defined(LIBTCC)
+#ifdef WIN32
+int __stdcall DllMain(void * hinstDLL, unsigned long fdwReason, void * 
+    if (fdwReason == 1/*DLL_PROCESS_ATTACH*/)
+    {
+    /* on win32, as implemented in main()
+       we suppose the lib and includes are at the location of this library
+    */
+        static char path[1024];
+        char *p, *d;
+        GetModuleFileNameA(hinstDLL, path, sizeof path);
+        p = d = strlwr(path);
+        while (*d)
+        {
+            if (*d == '\\') *d = '/', p = d;
+            ++d;
+        }
+        *p = '\0';
+        tcc_lib_path = path;
+    }
+    return 1 /*TRUE*/;
+#else /* !LIBTCC */
 static int64_t getclock_us(void)
 #ifdef WIN32

reply via email to

[Prev in Thread] Current Thread [Next in Thread]