Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How compile a DLL ? #32

Open
Zardoz89 opened this issue Oct 10, 2020 · 14 comments
Open

How compile a DLL ? #32

Zardoz89 opened this issue Oct 10, 2020 · 14 comments

Comments

@Zardoz89
Copy link

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 :

imagen

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)

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 10, 2020

Are you using autoload or are you importing the dll specifically?

@Zardoz89
Copy link
Author

I'm importing it with import "csv.so"; . The csv dll exposes some functions to read a CSV file and dump the values to a DIV array or struct. (Very useful to load a tilemap generated with tiled or avoid to have huge data tables inside the source file)
It's finding correctly the DLL, as I change the path or change the name, It throws correctly that can't find the DLL.

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 10, 2020

If you can share some code I may be able to help you get it working. It also depends on whether the dll is compiled as a c or cpp file as the name mangling is different. Also it could be platform dependant, but this relies on many different factors (although dlls actually work on all platforms).

Do the example dlls work / run correctly?

@Zardoz89
Copy link
Author

Zardoz89 commented Oct 10, 2020

It works flawless on the original DIV for MSDOS. You can take a look to the code here : https://github.com/Zardoz89/csvDll

I would make a minimal example program to test it correctly.

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 10, 2020

Dlls for DOS work slightly differently (for various reason). There are some subtle changes necessary to get the code to work, although this varies from platform to platform there are some instances where no code changes are required at all.

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 10, 2020

Are you able to compile and use the example included dlls?

@Zardoz89
Copy link
Author

I try with demo2.cpp that implements a new function called "addsqrt". Does exactly the same thing. I try to rename to demo2.c and compile a dll . On this case, when I hit compile on DIV ide, the whole ide crash with a Segmentation fault.

I tried with branches "master" and "old_master".

imagen

@Zardoz89
Copy link
Author

@CicTec suggested me to use his fork on the forum . I keep having the same problem, but at least the console log, shows something that could be useful :
imagen


If could be uselful :

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 10, 2020

Which build of DIV are you using?

SDL Version?
C++ or C ?

@Zardoz89
Copy link
Author

Zardoz89 commented Oct 10, 2020

Like I said, I compile "master" branch, "old_master" branch and @CicTec fork master branch.

SDL 2.0.10

@Zardoz89
Copy link
Author

Sorry for duplicating this here and the forum, but toying with @CicTec fork and doing some debug with fprintfs, looks that divlibrary(), divmain() and divend() functions aren't being called. So the DLL functions aren't registered.

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 11, 2020

Many of the div functions and options are set by cmake when compiling.

SET(HAS_DLL 0) # optional dll support

If this is not set, dlls will not load

@MikeDX
Copy link
Collaborator

MikeDX commented Oct 11, 2020

Also i asked if you were compiling using c or c++, not the branch. Using c or c++ is also a cmake option

@Zardoz89
Copy link
Author

I find that the problem is that my code it's being compiled using c++ and has missing extern "C" on divmain, divlibrary and divend functions. Fixing this, works fine with @CicTec fork. With the "master" or "old_master" branches of this repos, doesn't work (I compiled with HAS_DLL set 1), it crashes the IDE when try to compile the code with the import statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants