[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Odd problem when using variables defined in header fi
From: |
grischka |
Subject: |
Re: [Tinycc-devel] Odd problem when using variables defined in header files for a .dll |
Date: |
Fri, 10 Mar 2017 14:43:52 +0100 |
User-agent: |
Thunderbird 2.0.0.23 (Windows/20090812) |
William Hales wrote:
Thankyou, but this does not seem to work. I just tried adding:
__declspec(dllimport) extern WINDOW *stdscr;
...to the start of my main.c, and it did not change the resulting program
behaviour. (No warnings or errors either, and I'm using -Wall).
[Screenshot. Let's see if the mailing list supports this.]
Sure that doesn't work, no surprise ;)
Because in C, additional extern declarations for the same symbol (with
the same type) are allowed but do not override any non-extern definitions
before or after.
Therefor you need to change the already existing declaration, that
is in curses.h, just add the single word 'extern' in the right place:
@@ -395,9 +395,9 @@ typedef struct
#ifdef PDC_DLL_BUILD
# ifdef CURSES_LIBRARY
# define PDCEX __declspec(dllexport) extern
# else
-# define PDCEX __declspec(dllimport)
+# define PDCEX __declspec(dllimport) extern
# endif
#else
# define PDCEX extern
#endif
PDCEX int LINES; /* terminal height */
PDCEX int COLS; /* terminal width */
PDCEX WINDOW *stdscr; /* the default screen window */
Alternatively you could patch TCC to treat dllimport as extern
automatically (as do mingw or msvc). In tccgen.c:
@@ -7022,9 +7022,9 @@ static int decl0(int l, int is_for_loop_init)
if (ad.a.weak)
type.t |= VT_WEAK;
#ifdef TCC_TARGET_PE
if (ad.a.func_import)
- type.t |= VT_IMPORT;
+ type.t |= VT_IMPORT, btype.t |= VT_EXTERN;
if (ad.a.func_export)
type.t |= VT_EXPORT;
#endif
type.t |= ad.a.visibility << VT_VIS_SHIFT;
(If you want this to be part of the upcoming tcc 0.9.27 release,
feel free to apply such patch to our 'mob' branch).
Which you prefer.
Here is a batch file snippet to build pdcurses and demo with TCC:
tcc -I. -DPDC_DLL_BUILD -o pdcurses.dll -shared -rdynamic ^
pdcurses/*.c win32/*.c -include stdlib.h -ladvapi32
tcc -I. -DPDC_DLL_BUILD -lpdcurses -L. demos/firework.c
.\firework
pause
You can also run the demo directly from source code, like this:
tcc -I. -DPDC_DLL_BUILD -lpdcurses -L. -run demos/firework.c
You can even run the entire pdcurses + demo directly from source code
(which in fact doesn't require any changes to pdcurses or TCC):
tcc -I. pdcurses/*.c win32/*.c -ladvapi32 -luser32 -run demos/firework.c
(pdcurses from: https://github.com/Bill-Gray/PDCurses/archive/master.zip)
--- grischka
Regards, Hales
William Hales wrote:
Hello,
I have been having a problem with tcc when linking my project against a dll.
The dll and my project share variables through a header file. This works
fine with gcc, but when compiled with tcc my program and the dll end up with
completely unique copies of the variables in the .h file, rather than sharing
them.
tcc requires 'extern' on the application (program) side, for example
__declspec(dllimport) extern int foo;
-- gr