Community
Message Board

Chat room - users
Game Over
( 394431 downloads)
Work In Progress
( 523201 downloads)
Links

Code Exchange
Downloads
Tutorials
Add to Favourites

Submit news

DIV ARENA FORUMS
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: How compile a DLL
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 04:07 PM
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
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 05:33 PM


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.
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 06:16 PM


> 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.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 07:12 PM


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.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 08:10 PM


Here LEEME.TXT and README.TXT



Attachment: LEEME.TXT (8kB)
This file has been downloaded 154 times

Attachment: README.TXT (8kB)
This file has been downloaded 156 times

View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 08:55 PM


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
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 09:15 PM


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.
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 10:01 PM


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]
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 10:14 PM


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
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 11:20 PM


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;

}
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 10-10-2020 at 11:33 PM


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]
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 11:44 PM


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.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 10-10-2020 at 11:54 PM


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.
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 11-10-2020 at 12:57 AM


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.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 11-10-2020 at 07:23 AM


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)
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 11-10-2020 at 10:27 AM


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]
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 11-10-2020 at 10:50 AM


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. :)
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 11-10-2020 at 01:22 PM


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 :cool: 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


Screenshot_20201011_152114.png - 84kB

[Edited on 11-10-2020 by Zardoz]
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 11-10-2020 at 03:52 PM


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]
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 12-10-2020 at 06:39 PM


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 ?
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 12-10-2020 at 08:47 PM


Here is

Attachment: csv.zip (6kB)
This file has been downloaded 146 times

View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 12-10-2020 at 09:18 PM


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]
View user's profile View All Posts By User
Zardoz
DIV Junior
**




Posts: 13
Registered: 10-10-2020
Member Is Offline


[*] posted on 12-10-2020 at 10:19 PM


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.

View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 13-10-2020 at 06:09 AM


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 ...)
View user's profile View All Posts By User

  Go To Top

Powered by XMB
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 18]