tinycc-devel
[Top][All Lists]
Advanced

[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: William Hales
Subject: Re: [Tinycc-devel] Odd problem when using variables defined in header files for a .dll
Date: Wed, 8 Mar 2017 23:37:10 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46

On further inspection my problem has nothing to do with header files.  Apologies for suggesting that.

It appears that TCC allows functions to be shared across DLL boundaries, but not variables.  Instead the .dll and the .exe get completely different copies/views of any variables you attempt to share.

Attached is a _much simpler_ demonstration of this problem, using only tcc and a couple of source files.  One gets compiled into a dll, the other an exe.  A batch file that builds and runs the example is included, you just need to double click it.

This example uses __declspec(dllexport) and __declspec(dllimport) to no avail.  Included is also the latest version of TCC, compiled from git.

Interestingly, TCC cannot handle this being the first line of a file:

>  __declspec(dllexport) int Fred;

To work around this I have arbitrarily added a #include <string.h> line.  Any valid #include line seems to fix the problem.  Perhaps this is related to my issue?  This problem exists in both the latest tcc from git and tcc 9.26 .


What the output of the attached demo looks like:

|    Fred is an integer that should be shared between the dll and our exe.
|
|    Initial value of fred:
|        our view: 0
|        dll view: 0
|
|    After Fred was modified by a function in the dll:
|        our view: 0
|        dll view: 123
|
|    After Fred was modified by us:
|        our view: 456
|        dll view: 123

What the output should look like:

|    Fred is an integer that should be shared between the dll and our exe.
|
|    Initial value of fred:
|        our view: 0
|        dll view: 0
|
|    After Fred was modified by a function in the dll:
|        our view: 123
|        dll view: 123
|
|    After Fred was modified by us:
|        our view: 456
|        dll view: 456


Regards, Hales




William Hales wrote:
Hello grischka,

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.]

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




_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Attachment: tccdll_exampleB.zip
Description: Zip archive


reply via email to

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