extern "C" {
// function
// function
// function
// function
// function
}
Gambit
"Mathias Thorell" <Ti...@Telia.com> wrote in message
news:399A13F9...@Telia.com...
> The solution to this (as seen in the thread mentioned above) is to do
> this :
>
> extern "C" __declspec(dllexport) void __stdcall Foo(){
> // ...
> }
>
> (According to Hens Zimmerman)
>
> But the source I try to compile contains a LOT of functions, so is there
> an easier way that affects all sources ?
May I ask what exactly are you trying to do? Are you building a DLL that others will
need to use, specifically MSVC programmers? If so, then you need to worry about the
leading underscore. Otherwise, it should not matter.
The Borland linker/compiler prepends a leading underscore to __cdecl functions. But
this is only the linker name for the function. From code, you call the function
without using the underscore.
If you compile a static lib, then you should let the compiler/linker prepend the
underscore. When you use the lib, the linker will expect to see a leading underscore
in front of each functions name.
Harold Howe [TeamB]
http://www.bcbdev.com
PS: if you are trying to compile a static LIB that MSVC users can use, then you
should realize that this is nearly impossible to do.
Now, today I ran into the same problem when I tried to compile a huge
pile of .c-files disytributed as the HDF5 API. I tried to build it as a
.lib, but got underscores for all the functions, and the same thing
happened when I tried to make a dll out of it too.
The solution to this (as seen in the thread mentioned above) is to do
this :
extern "C" __declspec(dllexport) void __stdcall Foo(){
// ...
}
(According to Hens Zimmerman)
But the source I try to compile contains a LOT of functions, so is there
an easier way that affects all sources ?
TIA,
Mathias Thorell
Senior Flight test Engineer
Gripen, SAAB Technologies AB, Sweden
> May I ask what exactly are you trying to do? Are you building a DLL that others will
> need to use, specifically MSVC programmers? If so, then you need to worry about the
> leading underscore. Otherwise, it should not matter.
See my first postin, I'm trying to build a .lib file.
> The Borland linker/compiler prepends a leading underscore to __cdecl functions. But
> this is only the linker name for the function. From code, you call the function
> without using the underscore.
> If you compile a static lib, then you should let the compiler/linker prepend the
> underscore. When you use the lib, the linker will expect to see a leading underscore
> in front of each functions name.
The problem (?) is that the .c-files are calling functions from eachother, and the
linker can't solve the underscore/no underscore situation then.
> PS: if you are trying to compile a static LIB that MSVC users can use, then you
> should realize that this is nearly impossible to do.
I know, I know... ;-)
Anyway, at last I made it work !
I've tried the extern "C" solution with no success, the compiler said that the statement
was not terminated properly (or something like that).
But, in pure desperation, I put the #ifdef __cplusplus around it, and then, voila ! It
works !
I made the (stupid ?) assumption that my compiler always is a C++-compiler, but I was
wrong there...
Thanks for the help !
/Mathias
You should not need to strip the leading underbar in that case.
>Anyway, at last I made it work !
>I've tried the extern "C" solution with no success, the compiler said that
the statement
>was not terminated properly (or something like that).
>But, in pure desperation, I put the #ifdef __cplusplus around it, and then,
voila ! It
>works !
Glad you got it working. If extern "C" was the solution, then the problem
was caused by C++ name mangling. C++ functions are mangled with lots of
extra symbols. C functions are not (except for the leading underbar in
Borland __cdecl functions).
>Thanks for the help !
It doesn't sound like I provided any useful guidance, but you are welcome
nonetheless.