Page 1 of 1

Dll - error in file MyDll.def

Posted: 15 Mar 2013 20:37
by Vitaly Markov
Is key word "EXPORT" obsolescent may be?
The second compilation of project MyDLL is terminated with an error (VIP7.401):
error lnk2537 : Error 2537: 'c:\documents and settings\mydoc\visual prolog examples\dll\mydll\mydll.def' - Incorrect definition file syntax of token '' at line 1.
The cursor points on the first letter of word "EXPORT".
The content of file:

Posted: 16 Mar 2013 14:55
by Thomas Linder Puls
It is no longer necessary to use .def files (has not been for a long time), and since I can't really remember the details about them I will rather support the "new" way.

You use the #export to export a class. Which means that all predicates declared in that class are exported with the link name you have given them in the "as" part of the declaration:

Code: Select all

#export myExports   class myExports   predicates     entry : (integer X) -> integer Y language stdcall as "Entry".   end class myExports

Posted: 16 Mar 2013 17:23
by Kari Rastas
The keyword in the *.def file is EXPORTS not EXPORT.

The old def file style works still perfectly with DLLs produced with the present version. I have in one DLL project about 270 exported predicates. So far I have been to lazy to "teach" myself the new style. :-)


Posted: 17 Mar 2013 18:30
by Vitaly Markov
Thomas Linder Puls wrote:You use the #export to export a class. Which means that all predicates declared in that class are exported with the link name you have given them in the "as" part of the declaration:...
How to connect dll to dlluser-project statically?
Visual Prolog Example static "dll" is not correct.

Posted: 18 Mar 2013 9:11
by Thomas Linder Puls
The dll\myDllUser project works fine for me. What problem do you have?

Basically you declare the same predicates/class (without the #export) and then you link with the corresponding lib.

Also notice the toyIDE example and the article Encapsulating.htm in that directory.


Posted: 18 Mar 2013 17:57
by Vitaly Markov
Thomas Linder Puls wrote:The dll\myDllUser project works fine for me. What problem do you have?
Yes, this project works fine for me also. But I want to modify VIP-project example myDll+myDllUser.
I created new function "sum" in class myDll:

Code: Select all

class myDll predicates     touch : (string String) -> string Touched procedure (i) language stdcall as "touch".     sum : (integer, integer) -> integer  procedure (i,i) language stdcall as "sum". end class myDll   implement myDll clauses     touch(String) = string::concat(String, ", touched!").     sum(X,Y) = X+Y. end implement myDll
Building is Ok.
Then I try to call function "sum" in

Code: Select all

implement myDllUser clauses     run() :-         console::write(myDll::sum(2,3)),console::nl,         console::write(myDll::touch("Hello World")). end implement myDllUser
Building is Ok
Run in Window terminated with error, matter of course:
error lnk2525 : Error 2525: 'Obj\myDllUser.5F8AA354.obj' - undefined name 'sum'
What must I do now?
I should use "#export myDll" in file ?

Posted: 18 Mar 2013 19:03
by Thomas Linder Puls
Apparently, myDll uses the old strategy with a .def file.

So either you have to update the .def file, or delete it and then add #export myDLL (I would add it to the file that contains the goal).

I will update the myDLL (for some future release) examples, and if you like I can post the result here, but for a more flexible structure I would follow the ideas from toyIDE instead.

Posted: 19 Mar 2013 7:30
by Kari Rastas
I made a test with Markov Vitaly's example. Seems that the DEF-file's encoding must be ANSI, not UTF-8. Adding the new predicate (sum in this case) using VIP7.4 changes the encoding to UTF-8 and then in linking the system complains of an error on line 1. After changing the format to ANSI no problems in building the project and using the result through MyDllUser.

Posted: 19 Mar 2013 17:02
by Vitaly Markov
Thanks Thomas, thanks Kari
I collect examples for school-book.
If the structure of dll-project will be modified, then example about dll-project be excluded from content.

Posted: 20 Mar 2013 9:37
by Thomas Linder Puls
In any case, I have updated the dll examples, currently they look like the attachment.

(And they may of course change more in the future).

Thanks to Kari for revealing the utf-8/linker problem, which we will of course look into.

Posted: 21 Mar 2013 18:32
by Vitaly Markov
I have updated the dll examples
Thomas, you tried to repeat creation of this example in a Prolog7.4?
The structure of the created dll-project and the structure of a dll-example are not identical.
Main differences are:
- different file structure of the projects
- "#export export" is arranged in the file without the goal.

Posted: 22 Mar 2013 11:55
by Thomas Linder Puls
There are lots of ways to organize such programs.

The reason that I have moved the #export directives to the "goal" file is because then this file defines the entries to the dll, i.e. the goal and the exported entries.

But the #export directives could be placed "anywhere", as long as they are part of the DLL projects, but not part of the DLL-user projects.

Posted: 4 Jun 2013 7:54
by Thomas Linder Puls
This is fixed in Build 7402. IDE: Web -> Check for updates...

Posted: 21 Jun 2013 13:41
by Vitaly Markov
The creation of dll-project mydll is terminated with an error (VIP7.402):
fatal error lnk2505 : Fatal error 2505: Cannot create file 'c:\Documents and Settings\\ \mydll\Lib\mydll.lib', errno=2
"Bug is set" :shock: :D
I use Windows XP.
Must I use Windows7?

Posted: 26 Jul 2013 10:21
by Vitaly Markov
Must I use Windows7?
I installed Windows7-64 and dll-project is created!