Page 1 of 1

library is corrupt when calling predicates from C/C++ on both 64bit platforms

Posted: 2 Jul 2021 11:53
by jonasydy
A c/c++ 64bit project is set up to call predicates inside a visual prolog 10 project which is also 64bit. The c++ declaration is:

Code: Select all

 extern "C" wchar_t *  connection(const wchar_t * STR);
The predicates is:

Code: Select all

connection : (string STR) -> string ConnectionValid language stdcall as "connection".
and the def file was added with
EXPORTS
connection
The exported function "connection" has been found through tool dumpbin /exports, However, when the c++ project was compiled, it showed "error LNK1127 library is corrupt"(the lib file generated by visual prolog). I checked the similar code on both 32bit platforms, it worked well. Is there is a solution as my main program is large and is c++ 64bit?
Thanks
Jonasydy

Re: library is corrupt when calling predicates from C/C++ on both 64bit platforms

Posted: 2 Jul 2021 13:29
by Thomas Linder Puls
This is a know issue, which we are examining, but don't yet have a solution for.

You can however load the DLL dynamically using LoadLibrary in C++, but the details about this must be found in a C++ documentation.

Notice that your C++ declaration must have __stdcall modifier (it will not solve this problem, but is necessary nevertheless).

Also notice that returning a string is tricky, because Visual Prolog strings are garbage collected when they are no longer visible from Visual Prolog.

Finally notice that the preferred way to export DLL predicates from Visual Prolog is by means of the #exports directive (i.e. rather than having a DEF file). A standard VIP DLL project illustrates this.