www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - problem creating a 32-bit dll

reply "nezih" <nyigitbasi netflix.com> writes:
Hi everyone,
I am trying to create a 32-bit dll (on windows server 2012 
64-bit) for an odbc driver, but no luck so far. 64-bit version 
works just fine. I can also see that the functions I implemented 
(the setup/install api of odbc) are properly exported in the dll, 
but when I try to create a data source name (DSN) using the 
driver windows complains that the "setup routines for the driver 
are not accessible". When I build an 64-bit dll I don't get any 
errors. I use a makefile to build the dll using cygwin, and here 
is its output:

Administrator WIN-GGN7BN6N6R5 /cygdrive/c/workspace/presto-odbc
$ make clean installer ARCH=32
$ARCH is 32
$LIBCURL is /cygdrive/c/D/dmd2/windows/bin/libcurl.dll
rm -f *.obj *.exp *.lib *.ilk *.pdb presto.dll unittests
rm -f installer/win/32/*.exe
dmd -g -w -version=UNICODE -m32 -Luser32.lib client/*.d odbc/*.d 
driver/*.d -shared -ofpresto.dll
client\statementclient.d(102): Deprecation: function 
core.time.Duration.hours is deprecated - Please use split 
instead. hours was too frequently confused for total!"hours".
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : NOIUSER32.LIB
dmd -unittest -g -w -version=UNICODE -m32 -Luser32.lib client/*.d 
odbc/*.d driver/*.d test/*.d -ofunittests
client\statementclient.d(102): Deprecation: function 
core.time.Duration.hours is deprecated - Please use split 
instead. hours was too frequently confused for total!"hours".
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : NOIUSER32.LIB
cp /cygdrive/c/D/dmd2/windows/bin/libcurl.dll .
chmod 555 libcurl.dll
./unittests
Tests completed.


Thanks,
Nezih
Aug 26 2014
next sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 8/26/14, 7:48 AM, nezih wrote:
 Hi everyone,
 I am trying to create a 32-bit dll (on windows server 2012 64-bit) for
 an odbc driver, but no luck so far. 64-bit version works just fine.
To clarify: this project is http://github.com/prestodb/presto-odbc. BTW how do we get rid of that warning? Andrei
Aug 26 2014
prev sibling next sibling parent reply "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Tuesday, 26 August 2014 at 14:48:05 UTC, nezih wrote:
 Hi everyone,
 I am trying to create a 32-bit dll (on windows server 2012 
 64-bit) for an odbc driver, but no luck so far.
Are you using DMD32 with OPTLINK? If so, are you sure the first exported symbol doesn't accidentally have a leading underscore in the resulting DLL? I'm not sure in which DMD release this bug was fixed[1], but I've always had to work around it in my own OPTLINK-made DLLs. [1] https://github.com/DigitalMars/optlink/pull/10
Aug 26 2014
parent reply "nezih" <nyigitbasi netflix.com> writes:
I use optlink and I use the latest dmd: DMD32 D Compiler v2.066.0
And yes I see underscores in front of the exported symbol names. 
What's the workaround? And I just verified that the 64-bit 
version doesn't have those leading underscores.


On Tuesday, 26 August 2014 at 15:16:12 UTC, Jakob Ovrum wrote:
 On Tuesday, 26 August 2014 at 14:48:05 UTC, nezih wrote:
 Hi everyone,
 I am trying to create a 32-bit dll (on windows server 2012 
 64-bit) for an odbc driver, but no luck so far.
Are you using DMD32 with OPTLINK? If so, are you sure the first exported symbol doesn't accidentally have a leading underscore in the resulting DLL? I'm not sure in which DMD release this bug was fixed[1], but I've always had to work around it in my own OPTLINK-made DLLs. [1] https://github.com/DigitalMars/optlink/pull/10
Aug 26 2014
parent "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Tuesday, 26 August 2014 at 15:28:32 UTC, nezih wrote:
 I use optlink and I use the latest dmd: DMD32 D Compiler 
 v2.066.0
 And yes I see underscores in front of the exported symbol 
 names. What's the workaround? And I just verified that the 
 64-bit version doesn't have those leading underscores.
Ah, runtime linking code rarely accounts for leading underscores (the so-called Windows "system" convention), so that is probably your problem. First, make sure the symbols are marked extern(C) and not extern(Windows) or extern(System). The workaround I usually use is simply prepending a dummy symbol to each exported one. If the exported C symbols are *not* mixed in, just manually place a dummy symbol at the beginning of the module: --- export extern(C) void __optlinkdummy() {} --- If they are mixed in through a mixin template or a string mixin, use pragma(mangle, ...) or string concatenation, respectively, to place a uniquely named dummy export before each proper export. This robustly ensures that your proper export is never the first exported symbol. This is supposed to be fixed in the latest OPTLINK source code, so it's tragic that DMD 2.066 ships with an outdated version that still has this terrible bug :(
Aug 26 2014
prev sibling parent reply "kdmult" <kdmult ya.ru> writes:
On Tuesday, 26 August 2014 at 14:48:05 UTC, nezih wrote:
 Hi everyone,
 I am trying to create a 32-bit dll (on windows server 2012 
 64-bit) for an odbc driver, but no luck so far.
Create a text file presto-x86.def with contents as shown below and add it to your $(SOURCES). --- presto-x86.def --- LIBRARY EXETYPE NT SUBSYSTEM WINDOWS EXPORTS SQLAllocHandle SQLBindCol SQLBindParameter SQLBrowseConnectW SQLBulkOperations SQLCancel SQLCloseCursor SQLColAttributeW SQLColumnPrivilegesW SQLColumnsW SQLConnectW SQLCopyDesc SQLDescribeColW SQLDescribeParam SQLDisconnect SQLDriverConnectW SQLEndTran SQLExecDirectW SQLExecute SQLFetch SQLFetchScroll SQLForeignKeysW SQLFreeHandle SQLFreeStmt SQLGetConnectAttrW SQLGetCursorNameW SQLGetData SQLGetDescFieldW SQLGetDescRecW SQLGetDiagFieldW SQLGetDiagRecW SQLGetEnvAttr SQLGetInfoW SQLGetStmtAttrW SQLGetTypeInfoW SQLMoreResults SQLNativeSqlW SQLNumParams SQLNumResultCols SQLParamData SQLPrepareW SQLPrimaryKeysW SQLProcedureColumnsW SQLProceduresW SQLPutData SQLRowCount SQLSetConnectAttrW SQLSetCursorNameW SQLSetDescFieldW SQLSetDescRec SQLSetEnvAttr SQLSetPos SQLSetStmtAttrW SQLSpecialColumnsW SQLStatisticsW SQLTablePrivilegesW SQLTablesW ---------------------- I have tested with the following command line: dmd -g -w -version=UNICODE -m32 -Luser32.lib -shared -ofpresto.dll presto-x86.def client\json.d client\mockcurl.d client\prestoerrors.d client\queryresults.d client\statementclient.d client\util.d odbc\odbcinst.d odbc\sql.d odbc\sqlext.d odbc\sqltypes.d odbc\sqlucode.d driver\bindings.d driver\columnresults.d driver\driver.d driver\getinfo.d driver\handles.d driver\prestoresults.d driver\process.d driver\tableinfo.d driver\typeinfo.d driver\util.d
Aug 26 2014
parent reply "nezih" <nyigitbasi netflix.com> writes:
Thanks! That did the trick. Btw do you have any idea about 
getting rid of the linker's warning message about the user32.lib? 
I played with the LIB env variable in several ways and I also 
edited sc.ini to set the LIB but no luck so far.

dmd -g -w -version=UNICODE -m32 -Luser32.lib presto-x86.def  
client/*.d odbc/*.d driver/*.d -shared -ofpresto.dll
client\statementclient.d(102): Deprecation: function 
core.time.Duration.hours is deprecated - Please use split 
instead. hours was too frequently confused for total!"hours".
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 9: Unknown Option : NOIUSER32.LIB


On Tuesday, 26 August 2014 at 18:27:59 UTC, kdmult wrote:
 On Tuesday, 26 August 2014 at 14:48:05 UTC, nezih wrote:
 Hi everyone,
 I am trying to create a 32-bit dll (on windows server 2012 
 64-bit) for an odbc driver, but no luck so far.
Create a text file presto-x86.def with contents as shown below and add it to your $(SOURCES). --- presto-x86.def --- LIBRARY EXETYPE NT SUBSYSTEM WINDOWS EXPORTS SQLAllocHandle SQLBindCol SQLBindParameter SQLBrowseConnectW SQLBulkOperations SQLCancel SQLCloseCursor SQLColAttributeW SQLColumnPrivilegesW SQLColumnsW SQLConnectW SQLCopyDesc SQLDescribeColW SQLDescribeParam SQLDisconnect SQLDriverConnectW SQLEndTran SQLExecDirectW SQLExecute SQLFetch SQLFetchScroll SQLForeignKeysW SQLFreeHandle SQLFreeStmt SQLGetConnectAttrW SQLGetCursorNameW SQLGetData SQLGetDescFieldW SQLGetDescRecW SQLGetDiagFieldW SQLGetDiagRecW SQLGetEnvAttr SQLGetInfoW SQLGetStmtAttrW SQLGetTypeInfoW SQLMoreResults SQLNativeSqlW SQLNumParams SQLNumResultCols SQLParamData SQLPrepareW SQLPrimaryKeysW SQLProcedureColumnsW SQLProceduresW SQLPutData SQLRowCount SQLSetConnectAttrW SQLSetCursorNameW SQLSetDescFieldW SQLSetDescRec SQLSetEnvAttr SQLSetPos SQLSetStmtAttrW SQLSpecialColumnsW SQLStatisticsW SQLTablePrivilegesW SQLTablesW ---------------------- I have tested with the following command line: dmd -g -w -version=UNICODE -m32 -Luser32.lib -shared -ofpresto.dll presto-x86.def client\json.d client\mockcurl.d client\prestoerrors.d client\queryresults.d client\statementclient.d client\util.d odbc\odbcinst.d odbc\sql.d odbc\sqlext.d odbc\sqltypes.d odbc\sqlucode.d driver\bindings.d driver\columnresults.d driver\driver.d driver\getinfo.d driver\handles.d driver\prestoresults.d driver\process.d driver\tableinfo.d driver\typeinfo.d driver\util.d
Aug 26 2014
parent reply "kdmult" <kdmult ya.ru> writes:
On Tuesday, 26 August 2014 at 20:41:27 UTC, nezih wrote:
 Thanks! That did the trick. Btw do you have any idea about 
 getting rid of the linker's warning message about the 
 user32.lib? I played with the LIB env variable in several ways 
 and I also edited sc.ini to set the LIB but no luck so far.
Just remove -Luser32.lib from the command line.
Aug 26 2014
parent reply "nezih" <nyigitbasi netflix.com> writes:
but then does that mean the linker already link user32.lib?

On Wednesday, 27 August 2014 at 05:42:06 UTC, kdmult wrote:
 On Tuesday, 26 August 2014 at 20:41:27 UTC, nezih wrote:
 Thanks! That did the trick. Btw do you have any idea about 
 getting rid of the linker's warning message about the 
 user32.lib? I played with the LIB env variable in several ways 
 and I also edited sc.ini to set the LIB but no luck so far.
Just remove -Luser32.lib from the command line.
Aug 27 2014
parent "nezih" <nyigitbasi netflix.com> writes:
Answering my own question: seems like the 32-bit binary gets 
linked against user32.lib even though I don't specify 
-Luser32.lib, but I have to specify that for the 64-bit build.

On Wednesday, 27 August 2014 at 09:01:12 UTC, nezih wrote:
 but then does that mean the linker already link user32.lib?

 On Wednesday, 27 August 2014 at 05:42:06 UTC, kdmult wrote:
 On Tuesday, 26 August 2014 at 20:41:27 UTC, nezih wrote:
 Thanks! That did the trick. Btw do you have any idea about 
 getting rid of the linker's warning message about the 
 user32.lib? I played with the LIB env variable in several 
 ways and I also edited sc.ini to set the LIB but no luck so 
 far.
Just remove -Luser32.lib from the command line.
Aug 27 2014