mysql_real_connect() produces link errors lazarus / 16-Databases ---------------------------------------------------------------------- mbohn · 2010-04-12 13:19 OSX 10.6.3 fpc 2.4.0 console app (not using ide) MySQL 5.1.45 (on client) MySQL 5.1.44 (on server) stripped down test code: Code: [Select]//console app to test connection to a MySQL database //  using fpc 2.4.0 program TestMySQL;  {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, SysUtils,  mysql50; var HostName,UserName,Password,DataBaseName:pchar;     alloc,sock:PMySQL; begin   writeln('');   writeln('starting TestMySQL');   HostName:='...';   UserName:='...';   Password:='...';   DataBaseName:='...';   alloc:=mysql_init(PMYSQL(@qmysql));   (*  function prototype from mysql.inc:   function mysql_real_connect(mysql:PMYSQL; host:Pchar; user:Pchar; passwd:Pchar; db:Pchar;                port:cuint; unix_socket:Pchar; clientflag:culong):PMYSQL;extdecl;external mysqllib name 'mysql_real_connect'; *) //but then the next line produces link errors:   sock:=mysql_real_connect(alloc,hostname,username,password,databasena me,0,nil,0); mysql_close(sock); end. result from compile/link: Code: [Select]fpc project3.lpr Free Pascal Compiler version 2.4.0 [2009/12/20] for i386 Copyright (c) 1993-2009 by Florian Klaempfl Target OS: Darwin for i386 Compiling project3.lpr Assembling testmysql Linking project3 Undefined symbols:   "_mysql_real_connect", referenced from:       _PASCALMAIN in project3.o   "_mysql_fetch_row", referenced from:       _PASCALMAIN in project3.o   "_mysql_query", referenced from:       _PASCALMAIN in project3.o   "_mysql_close", referenced from:       _PASCALMAIN in project3.o       _PASCALMAIN in project3.o       _PASCALMAIN in project3.o       _PASCALMAIN in project3.o   "_mysql_init", referenced from:       _PASCALMAIN in project3.o   "_mysql_num_rows", referenced from:       _PASCALMAIN in project3.o   "_mysql_select_db", referenced from:       _PASCALMAIN in project3.o   "_mysql_store_result", referenced from:       _PASCALMAIN in project3.o   "_mysql_refresh", referenced from:       _MYSQL50_MYSQL_RELOAD$PMYSQL$$LONGINT in mysql50.o ld: symbol(s) not found An error occurred while linking Error: Error while linking Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled) Please note that in working with mysql3 I was able to connect with my db but not able to perform other mysql functions -- I suppose due to incompatibilities between 3 and 5. Thanks for any suggestions. ---------------------------------------------------------------------- mbohn · 2010-04-13 18:14 I have stripped down further my test case: Code: [Select]//console app to test connection to a MySQL database //  using fpc 2.4.0 program TestMySQL;  {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, SysUtils,  mysql50dyn; var alloc:PMySQL;     qmysql:Mysql_Res;     begin   alloc:=mysql_init(PMYSQL(@qmysql)); end. This one compiles and links ok but produces an "Illegal Instruction" error on run.