Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
How compile a DLL
I'm trying to port my CSV DLL to DIV DX . I used the new div.h and compiled with gcc csv.cpp -o csv.so -fPIC -funsigned-char -fpermissive -shared -O3 . It generates a
csv.so . So then I try to use on my DIV game and when I try to compile it, throws a "Unknown name" error when calling my exported functions.
Any idea why happens this ? I need to do changes to my code ?
NOTE: I'm trying this to my own compiled version of "old_master" branch (f57f75c) and with "master" branch (dc8b7e5)
Also, I put a issue on github : https://github.com/DIVGAMES/DIV-Games-Studio/issues/32
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Hello,
in the dll / examples folder you will find several examples on how to create all types of DLLs supported by DIV, which are briefly explained in the
LEEME / README.TXT files.
If you have already seen this info, show the implemented code if possible, to see what the cause is.
Alternatively try the latest published version with bugfix in this section if the DLL works (create a separate directory so as not to mix this version
with the repository version):
https://div-arena.co.uk/forum2/viewthread.php?tid=246
Regards.
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
> in the dll / examples folder you will find several examples on how to create all types of DLLs supported by DIV, which are briefly explained in
the LEEME / README.TXT files.
Where ?
I can'tt find any "readme" on https://github.com/DIVGAMES/DIV-Games-Studio/tree/master/dll... or https://github.com/DIVGAMES/DIV-Games-Studio/tree/master/dll
> If you have already seen this info, show the implemented code if possible, to see what the cause is.
Here is : https://github.com/Zardoz89/csvDll
Are the files : csv.cpp , csv.h and myint.h . This code works flawless with the original DIV 2 for MS-DOS.
> Alternatively try the latest published version with bugfix in this section if the DLL works (create a separate directory so as not to mix this
version with the repository version):
https://div-arena.co.uk/forum2/viewthread.php?tid=246
I try with the latest night build, the last commit on "master" branch (compiled by myself on Ubuntu 20.04) and the last commit on "old_master" branch
(again compiled by my self). I don't see any linux build on these thread, and I don't have anymore a Windows (and I really hate seting up a Windows to
work with C/C++) to build the DLL and try DIV DX Windows on Wine.
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Yes is master/dll directory.
mmm sure, the version is only for windows, you can download the code of this version to generate the build for linux yourself from my fork repository:
https://github.com/CicTec/DIV-Games-Studio
It includes all the following bugfixes and improvements not yet implemented in the official repository and present in this pull:
https://github.com/DIVGAMES/DIV-Games-Studio/pull/25
Ok, later I try your DLL code to see what the problem can be.
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Here LEEME.TXT and README.TXT
Attachment: LEEME.TXT (8kB) This file has been downloaded 226 times
Attachment: README.TXT (8kB) This file has been downloaded 229 times
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
Of course that I read it. Its the exactly same readme.txt that the original DIV 2 for MS Dos had. As I said before, I compiled a DLL for the original
DIV 2 for MS DOS, so I know what I'm doing. As I far I can see, for some reason the compiler refuses to know the registered new functions to the
language. I did a little test with the "demo2.cpp" that registers a dumb little function called "addsqrt".
I have more info on the GitHub issue : https://github.com/DIVGAMES/DIV-Games-Studio/issues/32
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Yes, I had seen, as Mike explained to you, the internal code of the DLL between DIV2 and DIVDX may need changes given the porting to the new
platforms.
Try to generate the build from the repository I indicated, containing bugfixes included for the DLLs, which still seem to have some problems to fix.
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
I just try with your fork . Also, I try with the "demo2.cpp" that simply adds a "addsqrt" function to the language. However gives more information on
the console that could be useful :
SDL KEY INIT
full screen: 0
[COMPILER: LEXICO] LOOKING FOR: demo2.so [BETA] [/opt/divdx]
[COMPILER: LEXICO] FOUND FILE: [demo2.so] [/opt/divdx/demo2.so] [/opt/divdx]
[COMPILER: LEXICO] NOT PACKEABLE FILE: [demo2.so] [/opt/divdx/demo2.so] [/opt/divdx]
IMPORT: DLL: 7f1984822904 1597 demo2.so
IMPORT: Looking for funcs in demo2.so
IMPORT (find_dll #1): Try to opening demo2.so
IMPORT (find_dll #2): Try to opening ./demo2.so
[COMPILER: LEXICO] LOOKING FOR: demo2.so [/opt/divdx/demo2.so] [/opt/divdx]
[COMPILER: LEXICO] FOUND FILE: [demo2.so] [/opt/divdx/demo2.so] [/opt/divdx]
[COMPILER: LEXICO] NOT PACKEABLE FILE: [demo2.so] [/opt/divdx/demo2.so] [/opt/divdx]
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Yes, I saw your report in issues at github.
From the log, the printf line appears:
fprintf (stdout, "IMPORT: Looking for funcs in% s \ n", name);
The next code is this:
nFuns = 0;
COM_export = CNT_export;
divcpe = DIV_ImportDll (name);
if (divcpe == NULL) return 0;
DIV_UnImportDll (divcpe);
//
if (nFuns == 0) return -1;
In practice DIV_ImportDll returns 0 or leaves nFuns at 0 (it doesn't matter anything), so the library doesn't actually load anything, hence the
"unknown name" error
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
I taking a look at the code ... Pretty confusing :
int ImportDll(char *name)
{
fprintf(stdout, "IMPORT: Looking for funcs in %s\n",name);
fflush(stdout);
nFuns=0;
COM_export=CNT_export;
divcpe=DIV_ImportDll(name);
if (divcpe==NULL) return 0; // HERE ARE MISING { } ? Why unload ALWAYS the DLL ?
DIV_UnImportDll(divcpe);
//
if (nFuns==0) return -1; // HERE : WHERE nFuns variable are filled with something that isn't 0 ? Looks that always will return -1 here
ImpDLL=(DLL*)malloc(sizeof(DLL)*nFuns);
if (ImpDLL==NULL) return 0;
nFuns=0;
COM_export=CMP_export;
divcpe=DIV_ImportDll(name);
if (divcpe==NULL) { free(ImpDLL); return 0; }
return nFuns;
}
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
Looking more and doing some debug with fprints, looks that CNT_export and CMP_export aren't being called. But I don't know why.
Edit: Looks that Demo2.cpp , divlibrary(), divmain() and divend() functiones aren't being called. So the DLL functions aren't registered.
[Edited on 10-10-2020 by Zardoz]
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
nFuns is a global var that is managed by some functions like CNT_Export that is called by DIV_ImportDll, so for some reasones this functions is not
called, nFuns is not updated (still 0) and DLL not import any symbol, with a error result.
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Try to add this function to your CPP code:
void __export divend(COMMON_PARAMS) {
// End of DLL
}
The README.TXT indicate that this function must be defined.
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
I did. Nothing happens.
Also, I add fprintfs to check if the functions are called :
void __export divlibrary(LIBRARY_PARAMS) {
fprintf(stdout, "demo2.cpp: divlibrary\n");
fflush(stdout);
COM_export("ADDSQRT",addsqrt,2); // The name of the function within the language
// is indicated, as well as it's pointer and the
// number of parameters it has.
}
void __export divmain(COMMON_PARAMS) {
fprintf(stdout, "demo2.cpp: divmain\n");
fflush(stdout);
GLOBAL_IMPORT();
}
void __export divend(COMMON_PARAMS) {
fprintf(stdout, "demo2.cpp: divend\n");
fflush(stdout);
}
These fprintfs aren't show on stdout. This make to think that divlibrary(), divmain() and divend() functions aren't being called by DIV.
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
There will be some other problem somewhere else, I haven't had time to analyze yet, I'll tell you where you can find the code so you can try to see if
you can locate the problem in the meantime:
src/other/divdll1.c
src/other/divdll2.c
src/divc.c from line 3187 (of my repository)
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
Eureka!
What I find its that the code on mikedll.c tries to load the symbols "divmain", "divlibrary" and "divend" from the dynamic lbirary. And it fails,
because the DLL that I'm generating, have the symbols mangled. For example "divlibrary" becomes "Z10divlibraryPFvPcPviE". I modified the code to try
to load this mangled symbol, and then works fine and the compiler understand the new function.
So, now, what i'm doing wrong when I compile the DLL that it's generating these mangled names ?
EDIT: This happens why i'm generating the DLL from "demo2.cpp". The C++ compile mangles the symbols. Simply renaming demo2.cpp to demo2.c and
compiling it, generates a valid dynamic library and DIV recognizes the new function correctly.
[Edited on 11-10-2020 by Zardoz]
EDIT: Or wraping with extern "C" the diblibrary, divmain and divend functions wolrk fine.
[Edited on 11-10-2020 by Zardoz]
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Well
I see that new DLL loader is mikedll.c, divdll1/2.c are old. however, it seems there is no support for windows, so DLLs would only work in Unix at the
moment.
Thanks for the report and glad you solved the problem.
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
I just try to use a dll with the original repository (master and old_master branch), now segfaults the IDE when try to compile the div program At least, with your fork, my csv.dll (correcytly compiled now) works fine and
reads CSV files to fill arrays and structs.
Also, I noticed that in your fork, this program segfaults the whole DIV ide. On the original repository, simply shows a list of 0's . Pre initializing
the array with 0, fixes it. Looks that could be a problem with arrays initialization ? :
Code: | program example_csv;
private
int data[20];
begin
for (y = 0; y < 2 ; y++);
for (x = 0; x < 10; x++)
write_int(0, x * 10, y * 10, 0, offset data[x + y*10]);
end
end
loop
frame;
if (key(_q) || key(_esc))
let_me_alone();
break;
end
end
end
|
[Edited on 11-10-2020 by Zardoz]
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
I should check, consider that the latest version published by me here:
https://div-arena.co.uk/forum2/viewthread.php?tid=246:
Which corresponds to this pull request not yet integrated:
https://github.com/DIVGAMES/DIV-Games-Studio/pull/25
Fixes over 40 bugs, several improvements such as source code formatting, printf for verbose debugging, etc ... compared to the latest master version
of the official repository.
I'll see if between tonight and tomorrow I can try your compiled DLL, I also use Linux at the moment and let's see if I can give you information about
the problem.
[Edited on 11-10-2020 by CicTec]
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Hello Zardoz,
Currently I can't compile your DLL, can you post here your DLL compiled for Linux with a complete example (the lastest reported) to try ?
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
Here is
Attachment: csv.zip (6kB) This file has been downloaded 252 times
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
Thanks, I've tried the example and work fine without any crash (IDE and program) on my Linux version of DIV DX, I've a build at 64 bit for Ubuntu
16.04 LTS 64 bit
Try to compile DIVDX from my repository with debug (I use it):
cmake -DDEBUG -DCMAKE_BUILD_TYPE=Debug .
To see the crash still existing.
[Edited on 13-10-2020 by CicTec]
|
|
Zardoz
DIV Junior
Posts: 13
Registered: 10-10-2020
Member Is Offline
|
|
I have it working fine. I think that the crash happened because I had mixed some system files from the main repository of DIV DX with the compiled
d-LINUX of your branch.
|
|
CicTec
DIV Pro
Posts: 471
Registered: 6-8-2016
Member Is Offline
|
|
I'm glad it works well for you now.
Yes most likely, I recommend using this build until Mike updates the master with the pull request.
If in the next few days I have some time, I'll try to continue with some other updates (bugfixes, better code formatting, etc ...)
|
|