1

I am trying to setup MingW and Code::Blocks on my Windows 8 64 bit laptop, and I'm facing some problem while building a main.cpp file. These are the versions that I have installed:

I've set the path to mingw64\bin in the environment variable. Also, in the Code::Blocks compiler settings, I have set path for all ToolChain Executables. There are two gcc in the MingW bin path. One is - gcc.exe and other is - x86_64-w64-mingw32-gcc.exe. Same for C++ Compiler, Linker for static and dynamic libs. Now when I try to build a simple Hello World file, it shows some errors:

obj\Debug\main.o -- In function swscanf  

c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\4.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'

obj\Debug\main.o -- In function `wscanf':

c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\4.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'

Similarly there are many errors and undefined references for - fwprintf, wprintf, std:cout, etc..

I'm sure there is some configuration problem, but I cannot find out what's the issue. Can any one take a look at the problem.

Here's the code I'm running:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

2 Answers 2

2

If you don't require 64 bit support, consider downloading "codeblocks-12.11mingw-setup.exe"
It packs its own 32 bit mingw and has everything preconfigured for you.

Otherwise, if you still need to compile amd64 apps:-
Assuming you extracted to D:\Mingw64, under the "Tool Chain Executables" tab, set the "Compiler's Installation Directory" to "D:\Mingw64\bin", Then click auto-detect to check whether code::blocks likes what it finds.

If everythings Ok, make sure the rest of the fields are as follows:-

C compiler: x86_64-w64-mingw32-gcc.exe
C++ compiler: x86_64-w64-mingw32-g++.exe
Linker for dynamic libs: x86_64-w64-mingw32-g++.exe
Linker for static libs: x86_64-w64-mingw32-ar.exe
Debugger: GDB/CDB Debugger... 
Ressource compiler: x86_64-w64-mingw32-windres.exe
Make program: mingw32-make.exe

Click on the "Additional Paths" tab and enter the following line:- (the path is correct for ver 4.7.4,the one you downloaded. It ends with 4.7.3)

D:\Mingw64\libexec\gcc\x86_64-w64-mingw32\4.7.3\ 

Click on the "Search directories" tab to the imediate left "Toolchain Executables"
Add the following paths:-

D:\Mingw64\include
D:\Mingw64\x86_64-w64-mingw32\include
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3\backward
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3\x86_64-w64-mingw32
D:\Mingw64\lib\gcc\x86_64-w64-mingw32\4.7.3\include

Click on the "linker" tab and add the following paths:-

D:\Mingw64\Lib 
D:\Mingw64\x86_64-w64-mingw32\lib

And finally click on the "Compiler Settings tab", Click on "Other options" and add:-

-m64

One last thing-> remember to save those settings to disk!
If it crashes while you test this new config, you might wish you had!
Do this (I think) either by "File->Save Everything" or restarting code::blocks ...without another instance running.

Try compiling something then share the outcome

2
  • Thanks for your reply. I did the changes for mingw64, but the same problem persists. Also, I didn't find all the paths you mentioned there. First, Linker for dynamic libs: was set to : x86_64-w64-mingw32-gcc.exe. And the one for static libs was set to: x86_64-w64-mingw32-gcc-ar.exe. Also, Resource Compiler was set to just: windres.exe. Then in Search Directory, I didn't find the paths - 3, 4, ad 5th. Those including C++. Rest all the settings I did. but the same error was coming. As far as your frst option is concerned, I will try that too.
    – Rohit Jain
    May 27, 2013 at 17:32
  • Oh dear :) Thank you so so much. Everything's working fine now. I changed the dynamic lib as you mentioned, and for static libs, I just set it to ar.exe. As I didn't have g++-ar.exe. And for C++, the path I added was directly inside the first include directory, which I used. And now, I'm seeing the output. Thanks once again :)
    – Rohit Jain
    May 27, 2013 at 18:12
0

Peace! Dear brother, I think you need this:

(1) std::cout << "Hello world!" << std::endl;

You need to put "std::function_name" whenever you are using a predefined function from iostream.h, because this is you way access it in GCC, which Code::Blocks uses.

(2) Try it compiling by omitting "using namespace std;" from your code. Because I've compiled C and C++ code many times in Code::Blocks on 32-bit Windows XP, and it did!

(3) Make sure the path is set to the directory "mingw\bin".

(4) Ensure if you have 64-bit MinGW installed and path set to its "bin" directory (if you want to compile for 64-bit). It will compile for 64-bit by default.

(5) Try the flags/arguments "-m32" and "-m64" for compiling for 32- and 64-big respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.