Compiling C++Builder project on command line

前端 未结 3 1647
离开以前
离开以前 2021-01-12 04:20

Is there a way to compile a C++Builder project (a specific build configuration) from the command line?

Something like:

CommandToBuild ProjectNameToBu         


        
相关标签:
3条回答
  • 2021-01-12 04:32

    There are different ways for automating your builds in C++Builder (as of my experience, I'm speaking about old C++Builder versions like 5 and 6).

    You can manually call compilers - bcc32.exe (also dcc32.exe, brcc32.exe and tasm32.exe if you have to compile Delphi units, resource files or assembly language lines of code in your sources) and linker - ilink32.exe.

    In this case, you will need to manually provide the necessary input files, paths, and keys as arguments for each stage of compilation and linking.

    All data necessary for compilation and linking is stored in project files and, hopefully there are special utilities, included in the C++Builder installation, which can automate this dirty work, provide necessary parameters to compilers and linker and run them. Their names are bpr2mak.exe and make.exe.

    First you have to run bpr2mak.exe, passing your project *.bpr or *.bpk file as a parameter and then you will get a special *.mak file as output, which you can use to feed on make.exe, which finally will build your project.

    Look at this simple cmd script:

    @bpr2mak.exe YourProject.bpr
    @ren YourProject.mak makefile
    @make.exe
    

    You can provide the real name of "YourProject.mak" as a parameter to make.exe, but the most straightforward way is to rename the *.mak file to "makefile", and then make.exe will find it.

    To have different build options, you can do the following:

    The first way: you can open your project in the IDE, edit options and save it with a different project name in the same folder (usually there are two project files for debug and release compile options). Then you can provide your building script with different *.bpr files. This way, it looks simple, because it doesn't involves scripting, but the user will have to manually maintain coherency of all project files if something changes (forms or units added and so on).

    The second way is to make a script which edits the project file or make file. You will have to parse files, find compiler and linker related lines and put in the necessary keys. You can do it even in a cmd script, but surely a specialised scripting language like Python is preferable.

    0 讨论(0)
  • 2021-01-12 04:41

    Use:

    msbuild project.cbproj /p:config=[build configuration]
    

    More specifics can be found in Building a Project Using an MSBuild Command.

    0 讨论(0)
  • 2021-01-12 04:52

    A little detail not mentioned.

    Suppose you have external dependencies and that the .dll file does not initially exist in your folder

    You will need to include the external dependencies in the ILINK32.CFG file. This file is usually in the folder

    C:\Program Files (x86)\Borland\CBuilder6\Bin\ilink32.cfg

    (consider your installation location)

    In this file, place the note for your dependencies.

    Example: A dependency for TeeChart, would look like this (consider the last parameter):

    -L"C:\Program Files (x86)\Borland\CBuilder6\lib";"C:\Program Files (x86)\Borland\CBuilder6\lib\obj";"C:\Program Files (x86)\Borland\CBuilder6\lib\release";"C:\Program Files (x86)\Steema Software\TeeChart 805 for Builder 6\Builder6\Include\";"C:\Program Files (x86)\Steema Software\TeeChart 805 for Builder 6\Builder6\Lib\"

    You will also need to include the -f command to compile.

    In cmd, do:

    //first generate the file.mak
    1 - bpr2mak.exe MyProject.bpr  
    //then compile the .mak
    2 - make.exe -f MyProject.mak
    

    You can also generate a temporary mak file with another name, as the answer above says, directly with bpr2mak

    bpr2mak.exe MyProject.bpr -oMyTempMak.mak
    
    0 讨论(0)
提交回复
热议问题