Skip to content

Commit 58b210a

Browse files
committed
fix: fix compiler errors on macOS, set DYLD_LIBRARY_PATH run param to fix wrong path for libssl
Refs #2238
1 parent 3213fe9 commit 58b210a

File tree

5 files changed

+51
-39
lines changed

5 files changed

+51
-39
lines changed

heidisql.lpi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<SessionStorage Value="InProjectDir"/>
88
<Title Value="heidisql"/>
99
<Scaled Value="True"/>
10+
<UseAppBundle Value="False"/>
1011
<ResourceType Value="res"/>
1112
<UseXPManifest Value="True"/>
1213
<XPManifest>
@@ -121,6 +122,15 @@
121122
</PublishOptions>
122123
<RunParams>
123124
<FormatVersion Value="2"/>
125+
<Modes>
126+
<Mode Name="default">
127+
<environment>
128+
<UserOverrides Count="1">
129+
<Variable0 Name="DYLD_LIBRARY_PATH" Value="$Path($(OutputFile))"/>
130+
</UserOverrides>
131+
</environment>
132+
</Mode>
133+
</Modes>
124134
</RunParams>
125135
<RequiredPackages>
126136
<Item>
@@ -443,6 +453,17 @@
443453
<OtherUnitFiles Value="source"/>
444454
<UnitOutputDirectory Value="bin\lib\$(TargetCPU)-$(TargetOS)"/>
445455
</SearchPaths>
456+
<Conditionals Value="// example for adding linker options on Mac OS X
457+
//if TargetOS=&apos;darwin&apos; then
458+
// LinkerOptions := &apos; -framework OpenGL&apos;;
459+
if TargetOS=&apos;darwin&apos; then
460+
CustomOptions := &apos;-WM10.15&apos;;
461+
462+
// example for adding a unit and include path on Windows
463+
//if SrcOS=&apos;win&apos; then begin
464+
// UnitPath += &apos;;win&apos;;
465+
// IncPath += &apos;;win&apos;;
466+
//end;"/>
446467
<Linking>
447468
<Debugging>
448469
<DebugInfoType Value="dsDwarf3"/>

source/apphelpers.pas

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ TAppSettings = class(TObject)
433433
function EscapeHotkeyPrefix(Text: String): String;
434434
function GetFileNameWithoutExtension(Filename: String): String;
435435
function GetCommandLine: String;
436-
function GetDynLibExtension: String;
437436

438437
var
439438
AppSettings: TAppSettings;
@@ -3072,14 +3071,6 @@ function GetCommandLine: String;
30723071
Result := Trim(Result);
30733072
end;
30743073

3075-
function GetDynLibExtension: String;
3076-
begin
3077-
Result :=
3078-
{$IFDEF WINDOWS}'dll'{$EndIf}
3079-
{$IFDEF LINUX}'so'{$EndIf}
3080-
{$IFDEF MACOS}'dylib'{$EndIf}
3081-
;
3082-
end;
30833074

30843075
{ Get SID of current Windows user, probably useful in the future
30853076
{function GetCurrentUserSID: string;

source/dbconnection.pas

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,9 @@ function TConnectionParameters.DefaultLibrary: String;
17711771
ngMSSQL: Result := 'MSOLEDBSQL'; // Prefer MSOLEDBSQL provider on newer systems
17721772
ngInterbase: begin
17731773
if IsInterbase then
1774-
Result := IfThen(GetExecutableBits=64, 'ibclient64.', 'gds32.') + GetDynLibExtension
1774+
Result := IfThen(GetExecutableBits=64, 'ibclient64.', 'gds32.') + SharedSuffix
17751775
else if IsFirebird then
1776-
Result := 'fbclient.' + GetDynLibExtension;
1776+
Result := 'fbclient.' + SharedSuffix;
17771777
end
17781778
end;
17791779
end;
@@ -1858,12 +1858,11 @@ function TConnectionParameters.GetLibraries: TStringList;
18581858
var
18591859
rx: TRegExpr;
18601860
FoundLibs: TStringList;
1861-
{$IfDef WINDOWS}
1861+
{$If defined(WINDOWS) OR defined(DARWIN)}
18621862
DllPath, DllFile: String;
18631863
Dlls {, Providers}: TStringList;
18641864
{Provider: String;}
1865-
{$EndIf}
1866-
{$IfDef LINUX}
1865+
{$ElseIf defined(LINUX)}
18671866
LibMapOutput, LibMap: String;
18681867
LibMapLines: TStringList;
18691868
{$EndIf}
@@ -1878,36 +1877,36 @@ function TConnectionParameters.GetLibraries: TStringList;
18781877
rx.ModifierI := True;
18791878
case NetTypeGroup of
18801879
ngMySQL:
1881-
{$If defined(LINUX)}
1880+
{$IfDef LINUX}
18821881
// libmariadb.so.0 (libc,...) => /lib/x86_64-linux-gnu/libmariadb.so
18831882
rx.Expression := '^\s*lib(mysqlclient|mariadb|perconaserverclient)\.[^=]+=>\s*(\S+)$';
1884-
{$ElseIf defined(WINDOWS)}
1885-
rx.Expression := '^lib(mysql|mariadb).*\.' + GetDynLibExtension;
1883+
{$Else}
1884+
rx.Expression := '^lib(mysql|mariadb).*\.' + SharedSuffix;
18861885
{$EndIf}
18871886
ngMSSQL: // Allow unsupported ADODB providers per registry hack
18881887
rx.Expression := IfThen(AppSettings.ReadBool(asAllProviders), '^', '^(MSOLEDBSQL|SQLOLEDB)');
18891888
ngPgSQL:
1890-
{$If defined(LINUX)}
1889+
{$IfDef LINUX}
18911890
rx.Expression := '^\s*(libpq)[^=]+=>\s*(\S+)$';
1892-
{$ElseIf defined(WINDOWS)}
1893-
rx.Expression := '^libpq.*\.' + GetDynLibExtension;
1891+
{$Else}
1892+
rx.Expression := '^libpq.*\.' + SharedSuffix;
18941893
{$EndIf}
18951894
ngSQLite: begin
1896-
{$If defined(LINUX)}
1895+
{$IfDef LINUX}
18971896
rx.Expression := '^\s*(libsqlite3)[^=]+=>\s*(\S+)$';
1898-
{$ElseIf defined(WINDOWS)}
1897+
{$Else}
18991898
if NetType = ntSQLite then
1900-
rx.Expression := '^sqlite.*\.' + GetDynLibExtension
1899+
rx.Expression := '^sqlite.*\.' + SharedSuffix
19011900
else
1902-
rx.Expression := '^sqlite3mc.*\.' + GetDynLibExtension;
1901+
rx.Expression := '^sqlite3mc.*\.' + SharedSuffix;
19031902
{$EndIf}
19041903
end;
19051904
ngInterbase:
1906-
rx.Expression := '^(gds32|ibclient|fbclient).*\.' + GetDynLibExtension;
1905+
rx.Expression := '^(gds32|ibclient|fbclient).*\.' + SharedSuffix;
19071906
end;
19081907
case NetTypeGroup of
19091908
ngMySQL, ngPgSQL, ngSQLite, ngInterbase: begin
1910-
{$If defined(LINUX)}
1909+
{$IfDEF LINUX}
19111910
// See https://serverfault.com/a/513938
19121911
Process.RunCommandInDir('', '/sbin/ldconfig', ['-p'], LibMapOutput);
19131912
LibMapLines := Explode(sLineBreak, LibMapOutput);
@@ -1916,8 +1915,8 @@ function TConnectionParameters.GetLibraries: TStringList;
19161915
FoundLibs.Add(rx.Match[2]);
19171916
end;
19181917
end;
1919-
{$ElseIf defined(WINDOWS)}
1920-
Dlls := FindAllFiles(ExtractFilePath(ParamStr(0)), '*.' + GetDynLibExtension, False);
1918+
{$Else}
1919+
Dlls := FindAllFiles(ExtractFilePath(ParamStr(0)), '*.' + SharedSuffix, False);
19211920
for DllPath in Dlls do begin
19221921
DllFile := ExtractFileName(DllPath);
19231922
if rx.Exec(DllFile) then begin
@@ -2283,11 +2282,11 @@ procedure TMySQLConnection.SetLockedByThread(Value: TThread);
22832282
if Value <> nil then begin
22842283
// We're running in a thread already. Ensure that Log() is able to detect that.
22852284
FLockedByThread := Value;
2286-
Log(lcDebug, 'mysql_thread_init, thread id #'+IntToStr(Value.ThreadID));
2285+
Log(lcDebug, 'mysql_thread_init, thread id #'+IntToStr(Integer(Value.ThreadID)));
22872286
FLib.mysql_thread_init;
22882287
end else begin
22892288
FLib.mysql_thread_end;
2290-
Log(lcDebug, 'mysql_thread_end, thread id #'+IntToStr(FLockedByThread.ThreadID));
2289+
Log(lcDebug, 'mysql_thread_end, thread id #'+IntToStr(Integer(FLockedByThread.ThreadID)));
22912290
FLockedByThread := Value;
22922291
end;
22932292
end;
@@ -3311,7 +3310,7 @@ procedure TMySQLConnection.DoBeforeConnect;
33113310
LibraryPath: String;
33123311
begin
33133312
// Init libmysql before actually connecting.
3314-
LibraryPath := Parameters.LibraryOrProvider;
3313+
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
33153314
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33163315
// Throws EDbError on any failure:
33173316
FLib := TMySQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3326,7 +3325,7 @@ procedure TPgConnection.DoBeforeConnect;
33263325
msg: String;
33273326
begin
33283327
// Init lib before actually connecting.
3329-
LibraryPath := Parameters.LibraryOrProvider;
3328+
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
33303329
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33313330
try
33323331
FLib := TPostgreSQLLib.Create(LibraryPath, Parameters.DefaultLibrary);
@@ -3357,7 +3356,7 @@ procedure TSQLiteConnection.DoBeforeConnect;
33573356
LibraryPath: String;
33583357
begin
33593358
// Init lib before actually connecting.
3360-
LibraryPath := Parameters.LibraryOrProvider;
3359+
LibraryPath := {$IFNDEF LINUX}ExtractFilePath(ParamStr(0)) + {$ENDIF} Parameters.LibraryOrProvider;
33613360
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
33623361
// Throws EDbError on any failure:
33633362
if Parameters.NetType = ntSQLite then

source/dbstructures.mysql.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ MYSQL_FIELD = record
162162
db: PAnsiChar; // table schema (added after 3.23.58)
163163
catalog: PAnsiChar; // table catalog (added after 3.23.58)
164164
def: PAnsiChar; // Default value (set by mysql_list_fields)
165-
length: {$IfDef LINUX} NativeUInt {$Else} LongInt {$EndIf}; // Width of column
166-
max_length: {$IfDef LINUX} NativeUInt {$Else} LongInt {$EndIf}; // Max width of selected set
165+
length: {$IfDef UNIX} NativeUInt {$Else} LongInt {$EndIf}; // Width of column
166+
max_length: {$IfDef UNIX} NativeUInt {$Else} LongInt {$EndIf}; // Max width of selected set
167167
// added after 3.23.58
168168
name_length: Cardinal;
169169
org_name_length: Cardinal;
@@ -181,7 +181,7 @@ MYSQL_FIELD = record
181181

182182
// Added in Oct 2023, to fix usage of mysql_fetch_lengths(). See issue #1863
183183
PMYSQL_LENGTHS = ^TMYSQL_LENGTHS;
184-
TMYSQL_LENGTHS = array[0..4095] of {$IfDef LINUX} qword {$Else} LongWord {$EndIf};
184+
TMYSQL_LENGTHS = array[0..4095] of {$IfDef UNIX} qword {$Else} LongWord {$EndIf};
185185

186186
MYSQL_ROW = array[0..$ffff] of PAnsiChar;
187187
PMYSQL_ROW = ^MYSQL_ROW;

source/dbstructures.pas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ constructor EDbError.Create(const Msg: string; const ErrorCode_: Cardinal=0; con
150150

151151
constructor TDbLib.Create(UsedDllFile, HintDefaultDll: String);
152152
var
153-
msg, ErrorHint: String;
153+
msg, ErrorHint, LoadErr: String;
154154
begin
155155
// Load DLL as is (with or without path)
156156
inherited Create;
@@ -161,12 +161,13 @@ constructor TDbLib.Create(UsedDllFile, HintDefaultDll: String);
161161
end;
162162

163163
FHandle := LoadLibrary(FDllFile);
164+
LoadErr := GetLoadErrorStr;
164165
if FHandle = NilHandle then begin
165166
msg := f_('Library %s could not be loaded. Please select a different one.',
166167
[ExtractFileName(FDllFile)]
167168
);
168-
if GetLastOSError <> 0 then begin
169-
msg := msg + sLineBreak + sLineBreak + f_('Internal error %d: %s', [GetLastOSError, SysErrorMessage(GetLastOSError)]);
169+
if LoadErr <> '' then begin
170+
msg := msg + sLineBreak + sLineBreak + LoadErr;
170171
end;
171172
if (HintDefaultDll <> '') and (ExtractFileName(FDllFile) <> HintDefaultDll) then begin
172173
ErrorHint := f_('You could try the default library %s in your session settings. (Current: %s)',

0 commit comments

Comments
 (0)