Board index » cppbuilder » [BCC32] DLL does not export symbol?

[BCC32] DLL does not export symbol?


2003-12-13 01:06:32 AM
cppbuilder20
Hi all,
I've been perusing the NG archives but couldn't seem to find clear-cut
info about this.
I'm basically trying to compile .c sources that were originally developed
under Linux with GCC to produce a .so file... Of course, I turn that into
a .dll here on Windows.
I had to adapt a few headers, and rewrite the Makefile, you can bet. I
test this out with a single .c file. The file is g_none.c. My compilation
line to obtain a .obj file is (this is intentionally wrapped):
bcc32 -c -v -O2 -ps -6
-I"C:\Borland\BCC55\Include" -I"..\..\include"
-og_none.obj g_none.c
Then to link:
bcc32 -L"C:\Borland\BCC55\Lib" -tWD -lv -lr g_none.obj -eg_none.dll
Now, my PROBLEM is:
- The .obj file contains all the non-static symbols just fine
- The .dll file contains none of them.
(This tested by invoking UNIX's strings utility on the files).
I saw stuff about some "__declspec(dllexport)" and stuff but I just have
NO CLUE WHATSOEVER about what this is :-/...
Anyone with a simple, just-a-few-steps failproof plan?
Thank you so much!
--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"Tant va la cruche ?l'eau qu'?la fin elle n'amasse pas mousse"
 
 

Re:[BCC32] DLL does not export symbol?

Quote
bcc32 -c -v -O2 -ps -6
-I"C:\Borland\BCC55\Include" -I"..\..\include"
-og_none.obj g_none.c
...
bcc32 -L"C:\Borland\BCC55\Lib" -tWD -lv -lr g_none.obj -eg_none.dll
Did you install the compiler in the manner shown in the readme file? If so
then why does a specification of an include search path of the compiler's
include directory appear on the command line and why does the specification
of a library search path of the compiler's lib directory appear on the
command line? Both of those are specified in the configuration files that
you create when you install the compiler.
Quote
I saw stuff about some "__declspec(dllexport)" and
stuff but I just have NO CLUE WHATSOEVER about
what this is :-/...
From the compiler's help file:
------------------------
__declspec(dllexport)
Category
Modifiers, C++Builder keyword extensions, Storage class
specifiers
Syntax
__declspec( dllexport ) declarator
The dllexport storage-class attribute is used for Microsoft C and
C++ language compatability. This attribute enables you to export
functions, data, and objects from a DLL. This attribute explicitly
defines the DLLís interface to its client, which can be the
executable file or another DLL. Declaring functions as dllexport
eliminates the need for a module-definition (.DEF) file, at least
with respect to the specification of exported functions.
Note: dllexport replaces the __export keyword
------------------------
Get this file, unzip it into the directories it creates and examine how the
DLL exports are handled.
www.mulroy.org/hello.zip
. Ed
Quote
Christophe Porteneuve wrote in message
news: XXXX@XXXXX.COM ...

I've been perusing the NG archives but couldn't seem to
find clear-cut info about this.

I'm basically trying to compile .c sources that were originally
developed under Linux with GCC to produce a .so file... Of
course, I turn that into a .dll here on Windows.

I had to adapt a few headers, and rewrite the Makefile, you
can bet. I test this out with a single .c file. The file is
g_none.c. My compilation line to obtain a .obj file is (this is
intentionally wrapped):

bcc32 -c -v -O2 -ps -6
-I"C:\Borland\BCC55\Include" -I"..\..\include"
-og_none.obj g_none.c

Then to link:

bcc32 -L"C:\Borland\BCC55\Lib" -tWD -lv -lr g_none.obj
-eg_none.dll

Now, my PROBLEM is:
- The .obj file contains all the non-static symbols just fine
- The .dll file contains none of them.

(This tested by invoking UNIX's strings utility on the files).

I saw stuff about some "__declspec(dllexport)" and stuff but
I just have NO CLUE WHATSOEVER about what this is :-/...
 

Re:[BCC32] DLL does not export symbol?

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in
Quote
Get this file, unzip it into the directories it creates and examine
how the DLL exports are handled.
Thanks Ed, it helped. I now *do* have a DLL that seems to export the
symbols I want. I tried dynamically linking to a procedure in it from
Delphi and invoking it, and this works.
Now, I face another issue. What I actually want to export from my DLL is
an array of function pointers (I didn't choose this interface, it was
imposed...).
So I've got this "gl_gd_table" array of several function pointers. It is
declared with __declspec(dllexport), which according to:
Quote
The dllexport storage-class attribute is used for Microsoft C and
C++ language compatability. This attribute enables you to export
functions, data, and objects from a DLL. This attribute explicitly
...should work. Indeed, it does show up when running the "strings" UNIX
utility on the .dll file.
The problem is, GetProcAddress does not return anything when invoked with
this symbol name. Somehow it makes sense: this is data, not a function.
Still, I didn't see a single API function retrieving *data* for me. In C,
I guess I'd use an "extern" declaration. But how can I do that for a
global data symbol in Delphi?!
I realize this group may now have become the wrong one. If so, let me know
and I'll be glad to repost in a more Delphi-related group.
--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"Good, Fast, Cheap: Pick two"
 

{smallsort}

Re:[BCC32] DLL does not export symbol?

If you post in a Delphi group then you're out of my view. I deal mostly
with Windows API code and Delphi is not where I spend much time.
You do not need to use Unix' strings utility to see the names of the items
exported by a dll. Use a command like this:
tdump -ee DllName.DLL
Win32 allows things which are data to be exported from a DLL. However I do
not know how to import them implicitly, with an import library or module
definition file.
I do know how to import them explicitly and an example is shown below:
----------MAINPROG.CPP-------------
#include <windows.h>
// to may the declarations easier to understand
typedef void (_stdcall *DllFunction)(int);
// the array of pointers to function
DllFunction *func_ptrs;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// load the DLL with code
HMODULE dll_hand = LoadLibrary("FUNCDLL.DLL");
// an alternative would be to link with an import library and do this
// HMODULE dll_hand = GetModuleHandle("FUNCDLL.DLL");
// but then do not use the FreeLibrary call and do not bother to
// test if the DLL is loaded
if (dll_hand == NULL) // if it didn't load
MessageBox(HWND_DESKTOP, "Cannot load DLL", "Error", MB_OK);
else
{
// get the array address
// note that C and C++ prepend an underscore to the name
// C++ has strict type checking so we have to cast the result
// because of the type that GetProcAddress returns
(FARPROC) func_ptrs = GetProcAddress(dll_hand, "_fptrs");
if (func_ptrs == NULL) // if the array was not found
MessageBox(HWND_DESKTOP, "Cannot load function array",
"Error", MB_OK);
else
{
for (int i = 0; i < 3; ++i) // call the functions
func_ptrs[i](i);
}
FreeLibrary(dll_hand); // unload the DLL
}
return 0;
}
--------------------------------------
----------FUNCDLL.CPP----------
#include <windows.h>
BOOL WINAPI DllEntryPoint(HINSTANCE, DWORD, LPVOID)
{
return TRUE;
}
// the various functions whose addresses will be
// placed into the array
__declspec(dllexport) void __stdcall Func1(int i)
{
char buf[10];
wsprintf(buf, "%d", i);
MessageBox(HWND_DESKTOP, buf, "Func1", MB_OK);
}
__declspec(dllexport) void __stdcall Func2(int i)
{
char buf[10];
wsprintf(buf, "%d", i);
MessageBox(HWND_DESKTOP, buf, "Func2", MB_OK);
}
__declspec(dllexport) void __stdcall Func3(int i)
{
char buf[10];
wsprintf(buf, "%d", i);
MessageBox(HWND_DESKTOP, buf, "Func3", MB_OK);
}
// same typedef as the calling program used
typedef void (_stdcall *DllFunction)(int);
// the array of function pointers
__declspec(dllexport) DllFunction fptrs[] =
{ Func1, Func2, Func3, NULL };
-----------------------------------------
If you copy those files to your disk you can build them with the following
commands and see for yourself that it works.
bcc32 -WDR -v funcdll
bcc32 -WR -v mainprog
. Ed
Quote
Christophe Porteneuve wrote in message
news: XXXX@XXXXX.COM ...

Now, I face another issue. What I actually want to export
from my DLL is an array of function pointers (I didn't
choose this interface, it was imposed...).

So I've got this "gl_gd_table" array of several function pointers.
It is declared with __declspec(dllexport), which according to:

The dllexport storage-class attribute is used for Microsoft C and
C++ language compatability. This attribute enables you to export
functions, data, and objects from a DLL. This attribute explicitly

...should work. Indeed, it does show up when running the
"strings" UNIX utility on the .dll file.

The problem is, GetProcAddress does not return anything when invoked with
this symbol name. Somehow it makes sense: this is data, not a function.
Still, I didn't see a single API function retrieving *data* for me. In C,
I guess I'd use an "extern" declaration. But how can I do that for a
global data symbol in Delphi?!

I realize this group may now have become the wrong one. If so, let me know
and I'll be glad to repost in a more Delphi-related group.

--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"Good, Fast, Cheap: Pick two"

 

Re:[BCC32] DLL does not export symbol?

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in
Quote
You do not need to use Unix' strings utility to see the names of the
items exported by a dll. Use a command like this:

tdump -ee DllName.DLL
Hey, thanks for that!
Quote
I do know how to import them explicitly and an example is shown below:
[...]
// get the array address
// note that C and C++ prepend an underscore to the name
// C++ has strict type checking so we have to cast the result
// because of the type that GetProcAddress returns
(FARPROC) func_ptrs = GetProcAddress(dll_hand, "_fptrs");
That's what I missed: I didn't know about the prefix "_". Now it works!
This is great, thanks.
I just have two distinct Makefiles now, one for Unix, one for Windows, but
the cross-compiling seems to work! =)
--
Christophe Porteneuve
Charg?d'Enseignement et de Projet
"Atheism is a nonprophet organization"