BCCOSX- C++跨OSX平台 编译器揭秘

  • A+
所属分类:[开发技巧]

    之前跟大家介绍都是Delphi下面支持64位OSX平台的编译器BCCOSX.EXE是C++下MAC OSX平台的编译器,他跟bCC32.exe是共享了基本代码的,如果你要想应用程序实现跨平台,那么你必须使用BCCOSX而不是BCC32.exe.

BCCOSX 与 BCC32的联系
大体上说,使用BCCOSX 与BCC32.exe基本相同,Windows系统下只能有BCC32.exe,除非你要要到mac OSX平台跑一跑:

--framework and -F
--sysinc (include paths)
--syslib (library paths)
--sysroot (system root)
-txxx (target options)
因为两个编译共享了一份底层代码,所以他们的命令语法只有很少的不相同。

BCCOSX 只不支持 structured exception handling (这个是Windows平台特有的).
命令行语法
bccosx [option [option...}] <filename> [<filename>...]使用空格来分来,编译器的名字,指令和文件的名字。之前可以用(-) 或者斜杠 (/)。例如:

BCCOSX -Ic:\code\hfiles你也可以指定 (.CFG) 文件, 看到的将会如下, BCCOSX.CFG File.

你可以使用 BCCOSX to 发送.O 文件 去连接. BCCOSX 也能支持汇编代码(参见-S 指令), 但是目前还不支持汇编在OSX系统下。

 

 BCCOSX 命令行帮助详细信息
To display the BCCOSX.exe command-line help in the cmd window, include the -h command-line option.

下面是在cmd窗口里面,查看到的BCCOSX.exe命令行信息,你可以用-h或者再多加一个 -去查看:

BCCOSX -hThe displayed list indicates the options that are enabled by default (*):

Embarcadero C++ 6.40 for OS X Copyright (c) 1993-2011 Embarcadero Technologies, Inc.
Available options (* = default setting, xxx = has sub-options: use -h -X):
(Note: -X- or -w-XXX will usually undo whatever was set or unset by -X or -wXXX.
 If two options conflict, the last one specified will be used.)
--sysroot Sets the logical root directory for headers, libraries and frameworks
   (Paths specified in --sysinc or --syslib and those in -F that begin
    with '/' are prefixed with this value)
--sysinc  Set the system include file search path
   (if specified, sysroot will be prepended)
--syslib  Set the system library file search path
   (if specified, sysroot will be prepended)
--framework Specifies a Mac OS X framework to link to (e.g. --framework=Carbon)
--savemem Set maximum SAVEMEM memory (in Mb)
   (This is the contiguous memory allocated to store global symbols and
    similar constructs.  Pre-compiled headers use this memory)
--version Show compiler version
--replacehdr Replace header name (e.g. --replaceHeader=a.h=b.h)
--xrtti   Generate extended rtti information
  -3      Generate 80386 protected-mode compatible instructions
  -4      Generate 80386/80486 protected-mode compatible instructions
  -5      Generate Pentium instructions
  -6      Generate Pentium Pro instructions
  -Axxx   Enable ANSI conformance
  -B      Compile to .ASM (-S), then assemble to .OBJ
  -Cxxx   Enable nested comments
  -D      -D<name> defines 'name' as a null string, or use -D<name>=<value>
  -E      Specify which assembler to use
  -F      Add the specified directory to the framework header search path
     For example, -F/System/Library/Frameworks;/Library/Frameworks
     NOTE: If --sysroot is specified, paths starting with '/' will have the value of --sysroot prepended.
  -G      Optimize for size/speed; use -O1 and -O2 instead
  -Hxxx   Generate and use precompiled headers
  -I      Set the include file search path
  -Jxxx   Template generation options
  -K      Set default character type to unsigned
  -L      Library file search path
  -M      Create a linker map file
  -N      Hodgepodge of miscellanity (see -h -N)
  -Nd     Macros get a value of "1" by default (-DX => -DX=1)
  -Nt     GNU __typeof(var) support
  -Nv     Allow void& as a valid type
  -O      Optimize jumps
  -P      Perform C++ compile regardless of source extension
  -Q      Extended compiler error information
  -Rxxx   Include browser information in generated .OBJ files
  -S      Compile to assembly
  -T      Specify assembler option, e.g. -Tx
  -U      Undefine any previous definitions of name
  -Vxxx   Compatibility options
  -X      Disable compiler autodependency output
  -Zd     Output global defs as DocBook specs; to specify: -Zd=<file>.c
  -Zn     Disable and/or don't define CodeGear builtins
  -Zx     Output global definitions to XML file.
       Sub Options:
  -Zx=<filename> Emit only types/declarations in <filename>
  -Zxf[=filename] Skip base type members
  -Zxm[=filename] Emit macros
  -Zxp[=filename] Emit file & line position
  -axxx   Set data alignment boundary.  Default is -a4; -a- means -a1
  -b      Enable -bi and treat enums as ints from a typechecking point of view
* -bi     Make sizeof(enum x) == sizeof(int) unless explicitly stated otherwise
  -c      Compile to object file only, do not link
  -d      Merge duplicate strings
  -dc     Put strings into the read-only data segment
  -dw     Put strings into the (writeable) data segment
  -e      Specify target executable pathname
* -ff     Fast floating point
  -fp     Correct Pentium FDIV flaw
* -fq     Use quiet floating point compare instruction (FUCOMP)
  -g      Stop batch compilation after n warnings (Default = 255)
  -h      Request help ('-h -' shows all help).  Can be specific: -h -V
  -i      Set maximum significant identifier length (Default = 250)
  -j      Stop batch compilation after n errors (Default = 50)
* -k      Generate standard stack frames
  -l      Pass options to the linker; example: -ls -l-x
  -m      Generate makefile dependency information
  -md     Put dependency info in .d files, not in the object file
  -mm     Ignore system header files while generating dependency info
  -mo     Specify the output file for dependency info
  -n      Set output directory for object files
  -o      Set output filename (-o<filename> or -o <filename> supported)
  -pxxx   Use Pascal calling convention
  -q      Suppress compiler identification banner
  -r      Use register variables
  -rd     Use register variables only when register keyword is employed
  -s      Link using the system's non-incremental linker
  -t      Specify target executable
* -u      Generate underscores on symbol names
  -vxxx   Turn on source debugging
  -w      Display all warnings
  -w!     Return non-zero from compiler on warnings
  -xxxx   Enable exception handling
  -y      Debug line numbers on
  -z      Options for redefining standard segment names
Use '-h <OPT>' for help on a specific option, or
    '-h -' to see all available options.
Displaying Help for Specific Options, Groups such as -Axxx and -Vxxx
You can get more specific information about each of the multiletter options, such as -Axxx (language compatibility and standards compliance) and -Vxxx (backward compatibility).

To do this, use the -h command-line option with the initial letter of the option group (such as -A to specify the -Axxx options). BCC32 will display only the help topics for the specified set of options (such as -Axxx, -Vxxx, or -Wxxx).

For example, to display a description of the -Axxx (language compatibility and standards compliance) options, use the -h and -A command-line options:

C:\>bccosx -h -A
Embarcadero C++ 6.40 for OS X Copyright (c) 1993-2011 Embarcadero Technologies, Inc.
Available options (* = default setting, xxx = has sub-options: use -h -X):
(Note: -X- or -w-XXX will usually undo whatever was set or unset by -X or -wXXX.
 If two options conflict, the last one specified will be used.)
  -A      Enable ANSI conformance
  -AF     Use SUN Forte keywords and extensions
  -AG     Use GNU keywords and extensions
  -AK     Use Kernighan and Ritchie (K&R) keywords and extensions
  -AT     Use CodeGear C++ keywords and extensions (also -A-)
  -AU     Use UNIX System V keywords and extensions
  -An     Use C99 keywords and extensions
  -Ax     Reserve keywords for future C++-0x extensionsIn the following example, the BCCOSX command-line help displays details about all the -Vxxx (backward compatibility) options:

C:\>bccosx -h -V
Embarcadero C++ 6.40 for OS X Copyright (c) 1993-2011 Embarcadero Technologies, Inc.
Available options (* = default setting, xxx = has sub-options: use -h -X):
(Note: -X- or -w-XXX will usually undo whatever was set or unset by -X or -wXXX.
 If two options conflict, the last one specified will be used.)
  -V      Compatibility options
* -VA     Generate all global functions in their own virtual/weak segment
  -VC     Do not mangle calling convention into symbols
  -VF     MFC compatibility
  -VF3    Support MFC 3.2
  -VF4    Support MFC 4.0
* -VI     Use Microsoft search algorithm to locate header files
  -VM     Microsoft Visual C++ compatibility
* -VP     PIC code generation
  -Va     Support old-style class arguments
  -Vb     Enable backward compatability with Bcc versions 5.8.2 and earlier
  -Vbc    Don't collapse reference to reference and allow qualified references
  -Vbe    Allow old-style explicit template specialization
  -Vbi    Follow C89 rules for immediates
  -Vbn    Allow calling of non-const or non-volatile member function for a const or volatile object
  -Vbo    Use old Borland overload resolution rules
  -Vbr    Allow old Borland rules for reference binding
  -Vbs    Treat string literals as non-const
  -Vbt    Use old Borland type rules for ternary operators
  -Vbu    Use old Borland rules for using in templates
  -Vbx    Allow explicit template specialization as a member function
  -Vc     Support constructor displacements
  -Vd     Use old C++ for-statement scoping rules
  -Ve     Zero-length empty base classes
  -Vg     Disable lexical digraph scanner
  -Vi     Use old 8.3 search algorithm to locate header files
  -Vl     Use old Borland class layout
  -Vm     Member pointer options
  -Vmd    Use the smallest possible representation for member pointers
  -Vmm    Support multiple inheritance for member pointers
  -Vmp    Honor declared precision of member pointers
  -Vms    Support single inheritance for member pointers
  -Vmv    Place no restrictions on where member pointers can point
  -Vn     Enable new operator names: and, or, and_eq, bitand, etc.
  -Vo     Set (almost) all compatibility flags; used with old code
  -Vp     Push 'this' first, as does Pascal
  -Vr     Reverse order for Multi-character constant
  -Vt     Put virtual table pointer at front of object layout
  -Vv     Use 'slow' virtual base pointers
  -Vw     Emit native code instead of Unicode for multi-byte character
  -Vx     Zero-length empty class members
Include Paths (-I, --sysinc)
BCCOSX resolves the include directives by searching the specified files in the standard include paths followed by the remote include paths.

Remote paths are relative to $(SYSROOT).

$(SYSROOT) is a Windows directory that represents the logical root of the Mac OS X machine. In this location are copied (cached) header files and dynamic libraries necessary for compiling and linking (see PAClient.exe).

The include paths can be controlled with the following options:

Option Include Path Type Description
-I standard Sets the standard include file search path.
--sysinc remote Sets the system (remote) include file search path. $(SYSROOT) is prepended to the specified path.

Remote paths are processed after standard paths are processed.

BCCOSX assumes that include directives of the form #include </...> (angle brackets, paths begin with forward slash) refer to the $(SYSROOT) location.

The commonly used include paths are described in the following table:

Include Path Type Path Description
standard $(BDS)\include\osx\crtl This directory contains C/C++ RTL header files (.h) provided by RAD Studio. Some of these files include C/C++ header files from $(SYSROOT)\usr\include. For more information, see OS X C RTL.
$(BDS)\include\osx\rtl This directory contains Delphi RTL machine generated header files (.hpp).
remote $(SYSROOT)\usr\include This directory contains C/C++ RTL Mac OS X header files cached on Windows.

To set the include paths from RAD Studio, see C++ Compiler Directories and Conditionals (for standard include paths) and Remote Profiles Panel (for remote include paths).
Library Paths (-L, --syslib)
Option Include Path Type Description
-L standard Library file search path.
--syslib remote Library file search path relative to $(SYSROOT).

Standard library paths and remote library paths are processed in the order specified. Thus you can control your library search path by interleaving -L and --syslib options to the compiler.
System Root (--sysroot)
SYSROOT is a directory on the Windows machine that represents the logical root of the remote/target machine. This directory is where files and/or symbolic information from the remote/target machine are cached. The SYSROOT value is used by BCCOSX.EXE to search for include and library files.

To change the SYSROOT value, use the --sysroot option and specify the directory on the development PC where you want the local cache copied.

To set the SYSROOT path from RAD Studio, see Remote Profiles.
Target Options for Cross-Platform Applications (--txxx)
BCCOSX supports the following cross-platform compiler options for specifying the target of a compilation (the -txxx command-line options):

To display command-line help for the -txxx options, enter: > bccosx -h -t.

Option Description
-t
 Specify target executable
-tC
-tCD
-tCDR
-tCDV
-tCR
-tCV
 Console application is target
Console DLL is target
Console DLL that uses dynamic RTL is target
Console DLL that uses the VCL is target
Console application that uses the dynamic RTL is target
Console application that uses the VCL is target
 
-tD
 DLL (shared library) is target (.dylib on Mac OS X)
-tM on Posix
(or -WM on Windows)
 Multithreaded application is target
-tP
 Package is target

Some of the -t options are not supported by BCC32, the C++ Command-Line Compiler for 32-bit Windows.
BCCOSX.CFG File
The configuration file for BCCOSX contains the following settings for the cross compiler:

-I"C:\Program Files\Embarcadero\RAD Studio\9.0\include\osx";"C:\Program Files\Embarcadero\RAD Studio\9.0\include\osx\crtl";"C:\Program Files\Embarcadero\RAD Studio\9.0\include\osx\rtl"
-I"C:\Program Files\Embarcadero\RAD Studio\9.0\dinkumware"
-L"C:\Program Files\Embarcadero\RAD Studio\9.0\lib\osx32\release"
--syslib=/usr/lib
--sysinc=/usr/include
-F/System/Library/FrameworksYou can create your own BCCOSX.CFG file and use it for compiling. The custom BCCOSX.CFG file must be placed in the current directory from where BCCOSX.EXE is invoked.

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar Anek 0

      留言是种美德,写点什么…