Author Topic: Command Line Compiling With CodeBlocks Installation of GNU Compilers  (Read 24332 times)

Offline freddie

  • Multiple posting newcomer
  • *
  • Posts: 11
This is my first question here even though I've been a member for some
time and am an avid CodeBlocks user. 

I'm trying to learn how to do command line compiling with my Windows
CodeBlocks Installation of the GNU Compiler Collection; specifically
gcc and g++.

I have two installations of the GNU compilers on my computers; the one
installed when I installed Dev-C++ Version 4.9.9.2 which is a pretty old
version of the compilers, and the one installed when I installed
CodeBlocks within the last year.

Here are the locations of the installations:

Dev-C++        C:\Dev-Cpp
CodeBlocks     C:\Program Files\CodeBlocks

I have been successful at command line compiling with the older Dev-C++
installed GNU compilers, but using the same techniques a successful
compile with the newer CodeBlocks compilers has eluded me.  Now, to be
absolutely clear - I'm not talking about using the CodeBlocks IDE to
compile; that works wonderfully; I'm speaking of compiling at the
Windows Command Prompt.

When I do this sort of work I create a batch file containing a change
directory command to change the directory to wherever I have my source
code, followed by an invocation of cmd.exe.  For example, here is my
batch file to start working with the older Dev-Cpp installed GNU
compilers for a Windows GUI template program of mine where the source is
in C:\Code\Dev-Cpp\Projects\Forms\Form1...

CD\
cd C:\Code\Dev-Cpp\Projects\Forms\Form1
C:\Windows\system32\cmd.exe

And if the source file is Main.cpp, here is my command line invocation
of g++ that successfully creates a Form1.exe file optimized for small
size...

C:\Dev-Cpp\bin\g++.exe Main.cpp -o"Form1.exe" -L"C:/Dev-Cpp/lib" -mwindows -s

However, using these same techniques using the CodeBlocks GNU binaries
totally fails.  I have attempted executing various PATH statements before
the command line to help things along but I never get any further than an
error message to the effect that the compiler can't find ld - even when
I've executed a PATH statement before invoking the compiler which contained
the exact PATH to ld which is...

C:\Program Files\CodeBlocks\MinGW\bin\ld.exe

I'm a bit experienced with command line compiling with Linux and I have
the book "An Introduction To GCC For The GNU Compilers gcc And g++" by
Brian Gough, but because the book seems entirely Linux/Unix based I'm
having a hard time understanding how to interpret it with Windows.

The conclusion I've come to though is that there has been some internal
changes to the compilers from the Dev-Cpp version to the newer CodeBlocks
installed version, (that's a no-brainer) that is not allowing the build
sequence to complete without access to some external OS dependent
information perhaps contained in environment variables.  Could someone help
me with this or provide information where I might learn how to set up my
environment in Windows 2000/XP to allow me to command line compile with
the CodeBlocks installed GNU compilers?

If I had to make a guess I suspect I have to add environment variables,
but I'm not entirely sure what they are or how to go about it.


Offline autobot

  • Single posting newcomer
  • *
  • Posts: 7
Re: Command Line Compiling With CodeBlocks Installation of GNU Compilers
« Reply #1 on: January 21, 2010, 03:22:49 am »
This is not a codeblocks related question but I imagine the reason is because the path to gcc/g++ contains spaces...reinstall it to c:/codeblocks and your issue will probably go away.

Offline freddie

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Command Line Compiling With CodeBlocks Installation of GNU Compilers
« Reply #2 on: January 21, 2010, 03:43:18 am »
Thanks for the input autobot.  Up until about 2 year ago I was somewhat opposed to installing anything at all to "Program Files" or using "Documents And Settings" in anyway whatsoever simply because I hated long directory names and especially file/directory names with spaces in them.  However, I've now given up on it.

Perhaps that is indeed my problem.  Supporting that idea is what I found out at the MinGW site specifically here....

http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite

related to installing the MinGW suite of binaries.  They state emphatically that unless you are very sure of what you are doing NOT to install the tools anywhere to directories with spaces in them. 

However, that makes me wonder how the Code::Blocks development team got Code::Blocks to Work in the first place with the default installation in C:\Program Files?  And it does work very well.  There has got to be a way to do it.  I forgot to mention that in my tests of this I did try putting my command line path parameters in "" quotes like so...

g++ "C:\Program Files\CodeBlocks\MinGW\bin\g++" .......etc

No luck.

Perhaps this isn't a CodeBlocks question, as you suggest.  If not, whose question is it then?

You've got me wondering though if I might try re-installing CodeBlocks to C:\CodeBlocks like you said.  I hate to re-install something that is basically working though.
« Last Edit: January 21, 2010, 03:46:14 am by freddie »

Offline TerryP

  • Multiple posting newcomer
  • *
  • Posts: 26
    • My journal
Re: Command Line Compiling With CodeBlocks Installation of GNU Compilers
« Reply #3 on: January 22, 2010, 03:47:43 am »
Perhaps its an issue of quoting?

I have MinGW/MSys installed into C:\DevFiles\Languages\MinGW and IDEs into C:\DevFiles, so there are no spaces in my paths; but I still take paranoid the lession of quoting, when writing scripts. I place them in to %UserProfile%\Programs\Batch\ and add them to my %Path%, so I can quickly launch a cmd window setup for a specific compiler (e.g. mingw, msvc, watcom). This allows having an unchanged cmd window for routine work, and saving per-tool changes for their own separate environment.

cmd treats "%ProgramFiles%" and %ProgramFiles% differently; the variable usually expands to C:\Program Files on English systems.
Just Another Computer Geek