Mail Archives: cygwin/1999/09/15/14:40:06
I have a 3rd party product which I have to use in my application.
It is Sybase Open Client lib. I created the .a from .lib:
----------------------
#!/bin/sh
if [ $# -ne 2 ]; then
echo "usage: mkimplib <dotlibfile> <dll>"
exit 1
fi
if [ \! -r $1 ]; then
echo "cannot read $1"
exit 1
fi
if [ \! -r $2 ]; then
echo "cannot read $1"
exit 1
fi
prep=`expr "$1" : '\(...\).*'`
libname=`expr "$1" : '\(.*\)\.lib'`
if [ "$prep" != "lib" ]; then
libname="lib"$libname
fi
libfile=$1
deffile=$libname.def
echo "EXPORTS" > $deffile
for s in `nm $libfile | grep '^........ T _' | sed 's/^........ . _//'`;
do
case $s in
DllMain*) ;;
*) echo $s ;;
esac
done >> $deffile
dlltool -k --add-stdcall-alias --def $deffile --dllname $2 --output-lib
$libname.a
------------------------
When I use the library in a program and link it to that it works
ok. An example:
-------------------------
----- testit.c
#include <stdio.h>
#include <errno.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
main()
{
int ret;
if ((ret = dbinit()) == FAIL)
fprintf(stderr, "ERROR dbinit() failed\n");
printf("dbinit() returned %d\n", ret);
return 0;
}
-----
% gcc -g -O2 -o testit.exe -I/c/Sybase/include testit.c -L/c/Sybase/lib
-lsybdb
% testit
dbinit() returned 1
---------------------------
The result is as expected. If I create a shared library which is doing
the stuff in main() above it fails in the dbinit() func.
---------------------------
----- xx.c
#include <stdio.h>
#include <windows.h>
int WINAPI DllEntryPoint(HANDLE h, DWORD reason, void *x)
{
return TRUE;
}
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
int Xx_Init()
{
int ret;
printf("in Xx_Init()\n");
ret = dbinit();
printf("dbinit() returned %d\n", ret);
return ret;
}
----- testit3.c
#include <stdio.h>
#include <errno.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <tcl.h>
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
main()
{
HINSTANCE handle;
int (*func)(void);
if ((handle = LoadLibraryA("libxx.dll")) == NULL) {
fprintf(stderr, "ERROR loading lib\n");
return -1;
}
if ((func = (int(*)(void))GetProcAddress(handle, "Xx_Init")) == NULL)
{
fprintf(stderr, "ERROR finding Xx_Init()\n");
return -1;
}
if ((*func)() == TCL_ERROR) {
fprintf(stderr, "ERROR calling dbinit()\n");
return -1;
}
printf("success\n");
return 0;
}
-----
% gcc -g -O2 -I/c/Sybase/include -c xx.c
% dllwrap --export-all --output-def libxx.def --entry _DllEntryPoint AT 12
--implib libxx.a -o libxx.dll
xx.o -L/c/Sybase/lib -lsybdb
Warning: no export definition file provided
dllwrap will create one, but may not be what you want
% gcc -g -O2 -o testit3.exe -I/c/Sybase/include testit3.c -L. -lxx
-L/c/Sybase/lib -lsybdb
% testit3
in Xx_Init()
0 0 [main] c:\TEMP\sybtest\x\testit3.exe 2592
handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
0 15271 [main] testit3 2592 handle_exceptions: Dumping stack trace
to testit3.exe.core
----------------------------
Am I'm doing something obviously wrong? Please help.
Regards
Tommy
--
------------------------------------------------------------------------
Thomas Kowatsch | - Senior Software Engineer -
Switching Test Solutions AG | mailto: thomas DOT kowatsch AT stest DOT ch
Wavetek Wandel & Goltermann Divison5 | web : http://www.stest.com
Friesenbergstr. 75 | Phone : +41 1 454-6731
CH-8055 Zuerich | FAX : +41 1 454-6612
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
- Raw text -