Recent

Author Topic: Cross compile to Cocoa x86_64  (Read 2855 times)

ChrisR

  • Full Member
  • ***
  • Posts: 103
Cross compile to Cocoa x86_64
« on: July 21, 2015, 01:05:40 pm »
Hello-
 How do I cross-compile from Lazarus 1.4.2 i386 on OS X 10.10 to a 64-bit application? I have followed the instructions at
  http://wiki.lazarus.freepascal.org/Cross_compiling#Cross_compiling_the_LCL
and I can successfully build an fpc program to x86_64, but lazbuild and the user interface always create i386. My program is set for the (presumably 64-bit compatible) Cocoa widgetset, and runs fine except is 32-bit. (by the way, the program has only one button with the following onClick:
"  {$IFDEF LCLCarbon}
     Showmessage('carbon');
  {$ENDIF}
  {$IFDEF LCLCocoa}
     Showmessage('cocoa');
  {$ENDIF}
  {$IFDEF CPU64}
    Showmessage('64');
  {$ENDIF}
  {$IFDEF CPU32}
    Showmessage('32');
  {$ENDIF} "

>fpc -Px86_64 test.pas
>./test: Mach-O 64-bit executable x86_64
>./test
DATE 2015/07/21
FPCTARGET x86_64
FPCTARGETCPU x86_64
FPCTARGETOS Darwin
FPCVERSION 2.6.4

lazbuild -B project1.lpr --ws=cocoa --cpu=x86_64 --os=darwin
file ./project1
  ./project1: Mach-O executable i386

------------
Here is the output of Lazbuild

primary config path: /Users/rorden/.lazarus
TBuildManager.SetBuildTarget Old=i386-darwin-carbon New=x86_64-darwin-cocoa FPC=True LCL=True
TBuildManager.SetBuildTarget Old=x86_64-darwin-cocoa New=x86_64-darwin-cocoa FPC=True LCL=False
TCompiler.Compile WorkingDir="/Users/rorden/Desktop/cocoa/" CompilerFilename="/usr/local/bin/ppc386" CompilerParams=" -Tdarwin -Px86_64 -MObjFPC -Scghi -O1 -g -gl  -k-framework -kCocoa -l -vewnhibq -Fi/Users/rorden/Desktop/cocoa/lib/x86_64-darwin -Fu/Developer/lazarus/lcl/units/x86_64-darwin/cocoa -Fu/Developer/lazarus/lcl/units/x86_64-darwin -Fu/Developer/lazarus/components/lazutils/lib/x86_64-darwin -Fu/Developer/lazarus/packager/units/x86_64-darwin -Fu/Users/rorden/Desktop/cocoa/ -FU/Users/rorden/Desktop/cocoa/lib/x86_64-darwin/ -dLCL -dLCLcocoa project1.lpr"
[TCompiler.Compile] CmdLine="/usr/local/bin/ppc386 -B  -Tdarwin -Px86_64 -MObjFPC -Scghi -O1 -g -gl  -k-framework -kCocoa -l -vewnhibq -Fi/Users/rorden/Desktop/cocoa/lib/x86_64-darwin -Fu/Developer/lazarus/lcl/units/x86_64-darwin/cocoa -Fu/Developer/lazarus/lcl/units/x86_64-darwin -Fu/Developer/lazarus/components/lazutils/lib/x86_64-darwin -Fu/Developer/lazarus/packager/units/x86_64-darwin -Fu/Users/rorden/Desktop/cocoa/ -FU/Users/rorden/Desktop/cocoa/lib/x86_64-darwin/ -dLCL -dLCLcocoa project1.lpr"
TBuildManager.MacroFuncInstantFPCCache /usr/local/bin/instantfpc
RunTool /usr/local/bin/instantfpc "--get-cache"
TBuildManager.MacroFuncInstantFPCCache /Users/rorden/.cache/instantfpc/
TExternalTool.DoExecute Title="Compile Project, CPU: x86_64, Target: project1" Process.CurrentDirectory="/Users/rorden/Desktop/cocoa/" Executable="/usr/local/bin/ppc386" Params:
-B
-Tdarwin
-Px86_64
-MObjFPC
-Scghi
-O1
-g
-gl
-k-framework
-kCocoa
-l
-vewnhibq
-Fi/Users/rorden/Desktop/cocoa/lib/x86_64-darwin
-Fu/Developer/lazarus/lcl/units/x86_64-darwin/cocoa
-Fu/Developer/lazarus/lcl/units/x86_64-darwin
-Fu/Developer/lazarus/components/lazutils/lib/x86_64-darwin
-Fu/Developer/lazarus/packager/units/x86_64-darwin
-Fu/Users/rorden/Desktop/cocoa/
-FU/Users/rorden/Desktop/cocoa/lib/x86_64-darwin/
-dLCL
-dLCLcocoa
project1.lpr

Hint: (11030) Start of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.6.4 [2014/02/26] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
(1002) Target OS: Darwin for i386
(3104) Compiling project1.lpr
(3104) Compiling unit1.pas
/Users/rorden/Desktop/cocoa/unit1.pas(16,28) Hint: (5024) Parameter "Sender" not used
(9001) Assembling (pipe) /Users/rorden/Desktop/cocoa/lib/x86_64-darwin/unit1.s
(9001) Assembling (pipe) /Users/rorden/Desktop/cocoa/lib/x86_64-darwin/project1.s
(9022) Compiling resource /Users/rorden/Desktop/cocoa/lib/x86_64-darwin/project1.or
(9015) Linking project1
(1008) 72 lines compiled, 1.8 sec
(1022) 3 hint(s) issued
[TCompiler.Compile] end

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7633
Re: Cross compile to Cocoa x86_64
« Reply #1 on: July 21, 2015, 01:46:38 pm »
Quote
TExternalTool.DoExecute Title="Compile Project, CPU: x86_64, Target: project1" Process.CurrentDirectory="/Users/rorden/Desktop/cocoa/" Executable="/usr/local/bin/ppc386" Params:
-B
-Tdarwin
-Px86_64
(my emphasis)

The "-P"  parameter only works for the "fpc" binary, not the ppc386 one.

Change your compiler to fpc not ppc386


kamischi

  • Full Member
  • ***
  • Posts: 177
Re: Cross compile to Cocoa x86_64
« Reply #2 on: July 21, 2015, 01:48:24 pm »
I think, the problem is that ppc386 is called as compiler. Maybe, try to set it explicitly with --compiler=ppcx64.
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

ChrisR

  • Full Member
  • ***
  • Posts: 103
Re: Cross compile to Cocoa x86_64
« Reply #3 on: July 21, 2015, 02:39:29 pm »
1.) OK, I was able to get a 64-bit executable by explicitly setting the compiler (full path required):

>lazbuild -B project1.lpr --ws=cocoa --cpu=x86_64 --os=darwin --compiler=/usr/local/bin/ppcx64
 > file ./project1
./project1: Mach-O 64-bit executable x86_64

2.) You can also set this up from the IDE:
 a.) Choose the Project/ProjectOptions menu item
 b.) In the CompilerOptions/CompilerCommands set the Compiler Command field to "/usr/local/bin/ppcx64"
 c.) For CompilerOptions/ConfigAndTarget set the "Target CPU family" to "x86_64"
 d.) For CompilerOptions/AdditionsAndOverrides store the "LCLWidgetType := cocoa" in the LPI

3.) Great work all those who have helped with the Cocoa widgetset - this is looking great!
« Last Edit: July 21, 2015, 02:48:55 pm by ChrisR »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Cross compile to Cocoa x86_64
« Reply #4 on: July 21, 2015, 07:40:26 pm »
Following marco's advice is better. Generally, fpc should be used instead. Lazarus will pass the correct -P to it and fpc will pick up the correct ppcXXX. If you change the compiler command to specific compiler, you will have to change it everytime you change the architecture, making multiple architecture build in one go impossible.