|
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:
|
tccdll_exampleB.zip
Description: Zip archive
[Prev in Thread] | Current Thread | [Next in Thread] |