I've been trying to link to an external DLL which is unfortunately compiled using MSVC in C++ mode. The functions itself do not use any C++ features, they are just not declared as extern "C" and thus use name mangling.
With MSVC name mangling, each symbol starts with a '?' character, which seems to not play well with fpc in some situations. Below are two test cases, where the first one works and the second one fails. If I remove the '?' from the external name, both test cases compile and produce an EXE with the proper imports.
Unfortunately, the second one is the interesting one as not using units is no option. Is this is a genuine bug or is a symbol containing a '?' not supported in units by design?
$ cat test.pas
program Test;
procedure Dummy; external 'who_cares' name '?Dummy';
begin
Dummy;
end.$ fpc test.pas
Free Pascal Compiler version 2.4.4 [2011/09/29] for x86_64 Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Win64 for x64
Compiling test.pas
Linking test.exe
7 lines compiled, 0.1 sec , 32464 bytes code, 1664 bytes data
$ cat test2.pas
program Test2;
uses TestUnit;
begin
Dummy;
end.
$ cat testunit.pas
unit TestUnit;
interface
procedure Dummy;
implementation
procedure Dummy; external 'who_cares' name '?Dummy';
end.$ fpc test2.pas
Free Pascal Compiler version 2.4.4 [2011/09/29] for x86_64 Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Win64 for x64
Compiling test2.pas
Compiling testunit.pas
Linking test2.exe
test2.pas(7,1) Error: Undefined symbol: ?Dummy
test2.pas(7,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
