Author Topic: build individual c++ file from command line  (Read 3311 times)

tir38

  • Guest
build individual c++ file from command line
« on: July 05, 2012, 07:51:48 pm »
I am trying to build an individual file from command line. I see the manual page here http://www.codeblocks.org/docs/main_codeblocks_en3.html#x3-380001.12 However, this is for building whole projects or workspace. Can  I do something for building individual files?When I run this, all it does is open Code::Blocks. It does no building

codeblocks.exe /na /nd --no-splash-screen --build myFile.cpp --target='output_file'

Offline PyTran++

  • Single posting newcomer
  • *
  • Posts: 5
Re: build individual c++ file from command line
« Reply #1 on: July 10, 2012, 11:14:20 pm »
In order to build/compile a C++ file (files with extension .cpp for example) you need a C++ compiler. While on Linux you can use GNU GCC, which actually is a container for several compilers. GCC selects the correct compiler based on the extension of the files you try to compile. Yes there exist other compilers (and containers), but this one is free, well-known and almost always directly available on Linux systems. The exact syntax for compiling depends on what you exactly want to do. You could for instance want to compile the C++ file into an executable by:

gcc filename.cpp -o executablename

This command compiles your C++ file named "filename" into an executable named "executablename". For a basic tutorial have a look at:

http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

For some basic information on flags have a look at:

http://users.encs.concordia.ca/~mokhov/comp444/tutorials/gcc.pdf