Thread: Changing compiler in IDE

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    203

    Changing compiler in IDE

    I'd like to upgrade to a newer version of the MinGW GCC compiler for use with Code::Blocks IDE. I'm considering downloading it from the following site that Xupicor had suggested: MinGW Distro - nuwen.net. Most of the links and on-line videos I've come across mention how to download and install C::B with GCC compiler but I haven't found anything meaningful about upgrading / adding a compiler. So please could someone advise re following steps before I download anything:
    1. C::B currently has MinGW GCC 4.9.2 installed, so according to the terminology of the following page, would it be considered an install or upgrade? MinGW Distro - nuwen.net
    2. do I need to unintall my current compiler before I download anything and, if so, what's the best way to do it. Above link says 'Simply delete C:\MinGW', it looks like some sort of cmd line prompt. Currently when I open my cmd window it reads C:\Windows\System32>. How do I navigate from here to going about deleting my current compiler if required
    3. back to this page: MinGW Distro - nuwen.net, which version should I download - the one with git (66.0 MB) or without (37.0 MB) - and what sort of name should I give the folder where the download is extracted (current one is C:\Program Files (x86)\CodeBlocks\MinGW, so perhaps C:\Program Files (x86)\CodeBlocks\MinGW 6.2?)
    4. the installation page MinGW Distro - nuwen.net mentions 'Finally, type g++ --version in your Command Prompt and hit Enter.' to check successful installation. Another command line prompt, which directory do I do this from?
    5. Assuming I have got this far, now we move on to C::B - Settings - Compiler - Copy - Please enter the new compiler's name : I enter GCC 6.2 (for e.g) - get a message 'New compiler has been added, don't forget to update the toolchain's executable page'
    6. So now I click Toolchain executables tab and Auto-detect or copy/paste C:\Program Files (x86)\CodeBlocks\MinGW 6.2 in the Compiler's installation directory text-box
    7. Same page view, Program Files tab, text boxes for the following are currently filled in: C compiler, C++ complier, Linker for dynamic libs, Linker for static libs, Debugger, Resource complier, Make program - do I leave these unchanged or do I need to do anything. First 3 and last text box currently reads mingw32-gcc.exe, Debugger reads GDB/CDB debugger : Default etc
    8. If I have missed anything along the way do let me know


    Many thanks

  2. #2
    Guest
    Guest
    1. An install I'd say
    2. I don't think so, your IDE probably allows you to have different compilers/toolchains next to each other. Look up the cd command for Windows. Also, you can right-click a folder in Windows Explorer and open a command prompt there. If you want to delete a folder, you should do it safely via the GUI instead of messing around with the command line.
    3. The one without git, you don't use it. IIrc, spaces in directory names can cause problems with such toolchains; consider using the C:\MinGW location suggested, or something similar.
    4. Anywhere, gcc should be in your PATH then.
    5. No idea
    6. No idea.
    7. Remember how these files are called and see if you can find their equivalent in your newly created MinGW 6.2 directory.
    8. No idea.

    Hope that helps at least a little bit
    Last edited by Guest; 12-09-2016 at 01:04 PM.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    I'm sure you can get it working Sean. I've used Code::Blocks and various MinGW distributions quite a bit. You just have to fiddle with it. If you've got a path wrong nothing bad will happen. Its just that when you try to build you'll get an error message or two or three or four or whatever in the output windows. I don't believe the MinGW setup programs put anything in the Windows Registry, so I suppose just deleting the folder would work. But as I recall the TDM MinGW installations have a setup program with a regular uninstall option, which of course would be preferable to use. I don't suppose that if MinGW is supplied with CodeBlocks though that you'll have that. If you uninstall CodeBlocks I guess it will take MinGW with it.

    On my main development box I used to have CodeBlocks setup to build with Microsoft's VC15 (from Visual Studio 2008), and using the x64 compiler. That took some tweaking, but I got it to work. I recently had to reinstall the OS on that box and I tried to get CodeBlocks compiling with VC19 (from VS 2015) but I couldn't get it and gave up. Turns out Microsoft made a real mess of things with their refactoring of the C Runtime (UCRT - Universal C Runtime), in that stuff is scattered in so many places its nearly impossible to figure where stuff is at.

    I might mention that I'm kind of burned out on IDEs and have been just compiling from the command prompt for a long time. So I'm just using IDEs as code editors. I usually use either CodeBlocks or NotePad++. You can set up batch files and it goes as quick as using the IDE.

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    I, like freddie, use batch files for both VC++ and the NUWEN distro


    1. NUWEN it is not an upgrade.
    2. If it was installed as part of the code::blocks installation and you are not going to use code::blocks
    NO
    3. For the NUWEN distro make sure you do not have a current C:\MinGW directory. If so rename it for now.
    Run the NUWEN setup and rename the MinGW it creates. I renamed it to C:\Nuwen-14.0
    If you had and renamed your mingw you can change it back now.
    4. It's your choice on downloads. I already had git installed so I di not need the NUWEN git version.
    If you plan on using git in your code development then by all means get the git version.


    I have no idea how to use code::blocks without it's included mingw compiler.


    As I use several different mingw compilers I NEVER set the path in the environment. If you have remove it.


    This is my nuwen g++ batch file. As I said I use several different versions of MinGW g++ so it has provisions for both 32 and 64 bit compiles. The NUWEN distro is 64bit only so don't let that throw you.
    It is also for Vista+
    You need to set the environment variable NUWEN64 to your NUWEN distro before calling this batch file:
    In my case:
    SET NUWEN64=C:\Nuwen-14.0
    Usage: NUWENGPP.BAT inputfile[no extension cpp assumed] -m64 [CON GUI DLL OBJ] ExtraFile1 ExtraFile2
    Note: ExtraFiles can be .a (import or static libraries) and .o (objectfiles)
    It will also compile and add a resource file to the exe if the resource file has the same base name as the c++ file.


    James


    Code:
    @setlocal
    @ECHO OFF
    REM NO longer supporting XP need to redefine _WIN32_WINNT and NTDDI_VERSION
    REM *********************************************************************
    REM MINGWGPP.BAT -> create Windows GUI, CON, OBJ or DLL using MinGW g++
    REM *********************************************************************
    REM Parameter 1 source file name no extension
    REM Parameter 2 should be -m64
    REM Parameter 3 should be CON for console GUI for windows OBJ for object module and dll for ...
    REM *********************************************************************
    REM ==============================================================================
    REM For use with Vista+
    SET WIN_VER=-DWINVER=_WIN32_WINNT_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA
    REM 
    REM ==============================================================================
    
    
    SET F=%~nx1
    REM *********************************************************************
    
    
    IF [%2] == [] GOTO usage
    IF [%3] == []   GOTO usage
    SET STATICLIB=-static-libgcc -std=c++14
    IF /I NOT [%2] == [-m64] GOTO usage
    
    
    SET MINGW=%NUWEN64%
    SET DISTRO=NUWEN
    
    
    IF /I [%3] == [CON] (
      SET GCCCFL= %STATICLIB%  -pipe -mconsole %2 -s -O2 -std=c++14 %WIN_VER%
      SET FTYPE="Windows Console App"
      SET OUTFILE="%F%.EXE"
    )
    
    
    IF /I [%3] == [GUI] (
      SET GCCCFL= %STATICLIB% -pipe -mwindows %2 -s -O2 -std=c++14 %WIN_VER%
      SET FTYPE="Windows Gui App"
      SET OUTFILE="%F%.EXE"
    )
    
    
    IF /I [%3] == [DLL] (
      SET GCCCFL= %STATICLIB%  -pipe -shared -s -O2 -std=c++14 %2 -Wl,--add-stdcall-alias,--output-def,"%F%.def",--out-implib,"lib%F%.a"
      SET FTYPE="Windows Dll"
      SET OUTFILE="%F%.DLL"
    )
    
    
    IF NOT DEFINED GCCCFL GOTO usage
    IF NOT EXIST "%F%.cpp" GOTO usage
    
    
    REM --------------------------------------------------------------------
    REM MINGW is set above to one of the NUWEN distros
    REM --------------------------------------------------------------------
    
    
    REM first check to see if this is a nuwen distro and set paths
    
    
    SET var=%cd%
    CD /D %MINGW%
    IF EXIST "set_distro_paths.bat" (
      CALL set_distro_paths
      SET DISTRO=NUWEN
    )
    CD /D %var%
    
    
    
    
    SET PATH=%MINGW%\bin;%PATH%
    SET INCLUDE=-I%MINGW%\include -I%MINGW%\include\sys
    SET LIB=%MINGW%\lib
    
    
    
    
    IF /I [%3] == [OBJ] (
      g++ %WARN% -c %2 %F%.cpp %WIN_VER% %4 %5 %6 %7 %8 %9
      GOTO done
    )
    
    
    
    
    IF NOT DEFINED GCCCFL GOTO usage
    IF NOT EXIST "%F%.cpp" GOTO usage
    
    
    
    
    
    
    SET LIBS=-lmingw32 -lgcc -lkernel32 -luser32 -lgdi32 -lcomctl32 -ladvapi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lwinmm -lcomdlg32 -limagehlp -lversion -limm32 -lwininet -lurlmon %LIBS%
    
    
    IF [%2] == [-m32] (
      SET RESTARGET=-Fpe-i386
    )
    
    
    REM --------------------------------------------------------------
    REM always use the %F%.rc file in the Res Directory if it exists
    REM this should handle both projects and individual files with resources
    
    
    IF EXIST "res\%F%.rc" (
      ECHO Compiling resources.....
      cd res
      windres -I. %WIN_VER% %RESTARGET% -i "%F%.rc" -o "%F%res.o"
      SET GRES="res\%F%res.o"
      cd ..
    ) ELSE (
      IF EXIST "%F%.rc" (
        ECHO Compiling resources.....
        windres -I. %WIN_VER% %RESTARGET% -i "%F%.rc" -o "%F%res.o"
        SET GRES="%F%res.o"
      )
    )
    REM --------------------------------------------------------------
    
    
    ECHO Compiling "%F%.cpp" to a  64bit %FTYPE% Using %DISTRO% Distro
    
    
    g++ %WARN% %GCCCFL% %INCLUDE% "%F%.cpp" %WIN_VER% -o %OUTFILE%  %GRES%  -static %4 %5 %6 %7 %8 %9 %LIBS%
    
    
    :fini
    
    
    ECHO Finished!
    IF EXIST "%GRES%" del "%GRES%"
    IF EXIST "%F%.o" del "%F%.o"
    IF EXIST libs.bat del libs.bat
    GOTO done
    :usage
    ECHO **************************************************************
    ECHO  Usage:  NUWENGPP.BAT MainFile -m64 [CON GUI DLL OBJ] ExtraFile1 ExtraFile2
    ECHO  Note:   ExtraFiles can be .a (import or static libraries) and
    ECHO          .o (objectfiles)
    ECHO     Use this batch file to easily create your g++ program
    ECHO **************************************************************
    :done
    endlocal

  5. #5
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    Many thanks for all your replies so far. I'll try to have a crack at this over Sunday into Monday and see how it goes. Thanks again

  6. #6
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148

    Angry

    I guess success isn't guaranteed. This post got me curious, and I decided to give it a go. On my Dell M6500 laptop I used it for years with CodeBlocks set up to use TDM_GCC4.8, x64. Before that, as I said, I had it set up to build with VC2008, x64. But then Microsoft trashed it so bad with their updates and GWX thing I had to redo the OS. As it stands now I'm just using CodeBlocks as my main editor, but I do have MSVC 2008 and TDM_GCC_4.8 installed. I couldn't get any of them setup to work! Argrrrr! Tried for an hour! What's really aggravating is I did have it set up years ago and it worked fine. I hope you get it working! Good luck!

    I was hoping I could get it set up and working and I could post for you my install paths for everything and what's filled in in the various compiler set up text boxes, but I failed!!!
    Last edited by freddie; 12-10-2016 at 11:35 AM.

  7. #7
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    Freddie: thanks for trying. Being self-taught and in a non-programming environment as such I find the infrastructure issues more daunting than coding. For code help I can always post snippets here and I usually get v good suggestions, but can't do the same with the hardware and such. Anyways, fingers crossed for tmrw, Mon and I'll report back how it goes.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Hopefully you'll have better luck than I, but if not, all is not lost. If you haven't ever tried, command line compiling as I and Jim does isn't hard. I've even written up a tutorial on it here...

    ProgEx43 : Command Line Compiling With The GNU Compilers

    ...which uses the GCC compiler toolchain. That you'll be able to get the MinGW toolchain working is a certainty once you run the setup program. After that test it out with something simple like a Dennis Ritchie "Hello, World" program. I have some of the command line strings and switches described at the link above. Once you get that working you can try some of Jim's batch files he posted.

  9. #9
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    Being self-taught and in a non-programming environment as such I find the infrastructure issues more daunting than coding.
    Me too. I hate fighting other folks stuff trying to get it to work.

    But this morning I tried my Win 10 Laptop, which I don't use very much as where I work we mostly use Win 7 yet, but I found I have TDM_GCC-64 installed on that, along with a recent Code::Blocks IDE only installation. I didn't remember setting it up but I must have. When I tested it I found it worked too. I was some concerned whether the setup was building 32 bit or 64 bit, so I tried this little test, and it output for me sizeof(void*) = 8...

    Code:
    #include <cstdio>
    
    int main()
    {
     printf("Hello, world!\n");
     printf("sizeof(void*) = %Lu\n",sizeof(void*));
     getchar();
    
     return 0;
    }
    ...so it looks like the x64 is working.

    I have TDM_GCC installed like so...

    C:\TDM-GCC-64

    I really hate hanging stuff right off my C Drive, but I hate more not having stuff work, so I left the installation put it there rather than someplace with spaces in the file name.

    So anyway, to get Code::Blocks to use that compiler (and I hadn't installed the Code::Blocks package that included the compiler, as, far as I know, it was still packaging the 32 bit version of the compiler with the IDE - and I wanted 64 bit builds), I believe I simply went to the ...

    Settings >>> Compiler

    ...menu selection, then in the top drop-down combo of the Global Compiler Settings dialog I chose 'GNU GCC Compiler'

    Then in the text box in about the middle of the form labeled 'Compiler's Installation Directory' I have listed...

    C:\TDM_GCC-64

    I don't recall but when I set it up (and I only have a vague recollection of doing it) I may have had to click that 'Auto-detect' button.

    In terms of all those other text boxes labeled C compiler, C++ compiler, linker, etc., I think they may get filled in when you do that auto-detect thing. That's where I was having trouble yesterday on my Win 7 box. Just couldn't get any of it right. I'll have to revisit it sometime where I have a cooler mindset. Hope this helps.

  10. #10
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I've been sticking with CMake and PowerShell for my build process and it's worked decently so far. It's kind of nice to decouple myself away from an IDE. It also makes the build process for both Linux and Windows relatively the same.

  11. #11
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    "Mixed bag" is how I'd describe the results of my efforts so far
    MinGW (GCC 6.1.0) - successful download, extraction and installation; had to add the location manually to PATH variable but it's there now
    changing C::B default compiler - stumbled here I'm afraid. I re-installed C::B and the IDE picks up the new compiler and updates all the toolchain executables program paths automatically except Debugger which still reads GDB/CDB debugger : Default. Under Settings->Debugger I Create Config a new GDB/CDB debugger but the problem is it's executable path is still showing as the C::B MinGW's gdb.exe and no matter how I try to change this (typing or through the select folder box) it goes back to the C::B MinGW's gdb.exe. And then when I try to compile any program using the new compiler but C::B MinGW gdb nothing happens
    freddie (post #9): what do you see in your debugger's executable path? also, all of the above was on Windows 8 but then I saw your post and thought I'd try it on a Windows 10 but here I ran into this Can&#39;t change environment variables in windows 10 - Super User
    Anyways, not to hijack my own thread, let's get back to C++: there are still a couple of positives from all this:
    Positive#1 the new C::B ships with a C++14 compiler, so now more custom make_uniques()!
    Positive#2 I can run the current MinGW that contains GCC 6.1.0 off cmd and I tried it with some C++17 code I found on-line. Code and output here:


    http://pastie.org/10981517 and it ran with the following warnings:
    Code:
    D:\>g++ -o HelloWorld HelloWorld.cpp //shouldn't call this HelloWorld, I know
    HelloWorld.cpp: In function 'std::ostream& cpp17::print(ARGS&& ...)':
    HelloWorld.cpp:6:74: warning: fold-expressions only available with -std=c++1z or
     -std=gnu++1z
         std::ostream& print( ARGS&&... args ) { return ( std::cout << ... << args )
     ; }
    Next steps When I can manage some chunk of time and focus I'll take a look at setting up batch files as everyone (John, Freddie, Jim) is doing
    Many thanks to each of you for your help and suggestions

  12. #12
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Don't get into Batch. M$ is pushing PowerShell now. Plus, PowerShell has a lot of nice Linux aliases so if you know Linux, you'll be write at home. My PS scripts have been super simple though. Just `cmake -G "My config" ..; msbuild /maxcpucount:4 project_name.sln`

  13. #13
    Registered User
    Join Date
    Dec 2010
    Location
    Trinidad, CO (log cabin in middle of nowhere)
    Posts
    148
    freddie (post #9): what do you see in your debugger's executable path?
    Can't help you on that one. I don't use the debugger (I log debug output to text files).

    From some of the stuff you wrote it almost sounds to me like you installed a Code::Blocks package that includes some version of MinGW, then installed another version of MinGW too? That's doable but somewhat awkward, which Jim Fuller alluded to about never setting the PATH. Problem is if you do that is it can be kind of tricky to know which compiler is being used on a build. I'm hoping you didn't do that but wasn't sure from your post. There are Code::Blocks downloads that don't include MinGW.

    I've found a lot of these settings from the IDE are tricky and sticky. I'm guessing some of their code isn't the best. Let me just give an example. I used Code::Blocks and an older MinGW distribution in 32 bit for years and years, and accumulated hundreds of projects. Then later when I became interested in 64 bit I tried to use the same project files but it doesn't work. All the libraries have to be changed in the CodeBlocks IDE (I'm not talking about the libraries CodeBlocks uses, but my project's libraries), and the CodeBlocks GUI has an interface for that when you go to the project's libraries tab. Only thing is it works terribly, terribly poorly. Many times you have to keep re-selecting them in the IDE, and doing several total shutdown and restarts of CodeBlocks before it finally 'keeps' the changes. After going through this a number of times I found it was about 15 times easier to just completely delete every project file CodeBlocks created and rebuild the project from scratch. Its just suboptimal coding that causes issues like that.

  14. #14
    Registered User
    Join Date
    Mar 2016
    Posts
    203
    Thanks, unlike Jim who's using several different MinGW compilers, I've only got one MinGW compiler in my root C:\ that is included in PATH and the C::B MinGW is within C:\ProgramFilex(x86)\CodeBlocks\MinGW\MinGW\bin and not this C::B compiler is not included in the PATH
    I'll play around with my 2 new shiny toys for X-mas (C::B with C++14 and GCC 6.1.0) and, when I can, take a look at some other alternatives to IDEs. Thanks to all once again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2010, 10:02 PM
  2. Replies: 4
    Last Post: 09-12-2009, 01:10 PM
  3. Changing GCC compiler in CDT
    By raj09 in forum Tech Board
    Replies: 1
    Last Post: 07-27-2009, 10:06 AM
  4. Replies: 2
    Last Post: 02-04-2008, 02:34 AM
  5. Changing windows without changing?
    By Lionmane in forum Windows Programming
    Replies: 7
    Last Post: 10-19-2005, 11:41 AM

Tags for this Thread