Author Topic: [Fixed]I could compile it in MS VC++6.0 while failed in codeblocks  (Read 7002 times)

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Hey all:
I'm new here and this is my first post.I'm now learning C++ from scratch in school,and yesterday I completed a task using VC++ 6.0 in school,which showed a GUI with a red line "I love BLEACH".However,when I compiled it in codeblocks at home,.obj file was available while linking failed.What's more,it showed many strange words(what you see here is what I saw in my PC):
Code: [Select]
Compiling: C:\Documents and Settings\Administrator\naoxi.cpp
Linking console executable: C:\Documents and Settings\Administrator\naoxi.exe
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x8c)锛氬鈥楪[email protected]鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x229)锛氬鈥楽[email protected]鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x23e)锛氬鈥楪[email protected]鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x2c6)锛氬鈥楥[email protected]鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x311)锛氬鈥楾[email protected]鈥欐湭瀹氫箟鐨勫紩鐢t2:ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings

And my source file(naoxi.cpp):
Code: [Select]
#include<windows.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="Hello";
char lpszTitle[]="I love BLEACH";


wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;


if(!RegisterClass(& wndclass))
{
MessageBeep(0);
return FALSE;
}

hwnd=CreateWindow(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW ,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(& Msg,NULL,0,0))
{
TranslateMessage(& Msg);
DispatchMessage(& Msg);
}
return Msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;

HFONT hF_black;
PAINTSTRUCT ps;
TEXTMETRIC tm;
char lpsz_1[]="I love BLEACH";
int X=0,Y=0;
int i;


switch(message)
{case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetTextColor(hdc,RGB(255,0,0));
GetTextMetrics(hdc,&tm);
    
Y=Y+tm.tmHeight+tm.tmExternalLeading;
hF_black=CreateFont(
0,
0,
0,
0,
FW_HEAVY,
0,
0,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE, "gerry");
        for(i=0;i<200;i++)
{Sleep(5);
TextOut(hdc,X+i,Y,lpsz_1,13);
InvalidateRect(hwnd,NULL,1);

}
break;

        



case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}





So what's wrong with this?Could you help me,Please? :(
P.S.:I use windows xp sp2.
« Last Edit: May 15, 2010, 06:33:29 am by YZMSQ »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #1 on: May 13, 2010, 08:03:59 pm »
The first thing you should do is turn on full commandline logging to see what is sent to the compiler:
change "Settings -> Compiler and debugger... -> Global compiler settings -> [the compiler you use] -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline".

And tell us which version of C::B and MinGW you use.

Some versions of MinGW do not like spaces or not english-characters in the file-paths.

It seems to be a linker problem.
To get a more meaningful output, you should try to compile/link a debug-version, where symbols are created and not stripped.

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #2 on: May 14, 2010, 12:03:10 pm »
Hi,thank you for your reply,I just downloaded C::B(with mingw) from your official webpage recently without any modification ("gcc -v" shows "3.4.5")~~~And what's more,when I download the latest mingw packages from sf.net(gcc 4.5),I still fail to build that c++ file just from command line in cmd.exe.
So,I doubt whether it's my source file that causes this issue.What about the result in your PC when compiling my c++ file? :shock:
« Last Edit: May 14, 2010, 12:10:35 pm by YZMSQ »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #3 on: May 14, 2010, 12:15:05 pm »
I can compile it (cross-compiler on linux), but I use the actual trunk from svn (or more exactly the nighly build from my repo).
I suggest using a recent nightly build (http://forums.codeblocks.org/index.php/board,20.0.html) and TDragons MinGW 4.4 (http://www.tdragon.net/recentgcc/).

Did you try to use a path with no spaces and just ascii-characters (no spaces, no chinese characters) ?

And you sould post the build-log after switching to full commandline logging.

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #4 on: May 14, 2010, 12:48:22 pm »
Hi,I just reinstall my C::B,and have nighly build package installed,and leave gcc not updated(gcc 3.4.5).This time it shows some clear errors in build log:

Code: [Select]
mingw32-g++.exe -fexec-charset=GBK    -c "C:\Documents and Settings\Administrator\naoxi.cpp" -o "C:\Documents and Settings\Administrator\naoxi.o"
mingw32-g++.exe  -o "C:\Documents and Settings\Administrator\naoxi.exe" "C:\Documents and Settings\Administrator\naoxi.o"  
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x1a1): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x36d): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x385): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x414): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x47a): undefined reference to `[email protected]'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
5 errors, 0 warnings
 

Still failed.I am not clear about the"undefined reference"~~~ :o
BTW,I haven't used a path with chinese-characters. :lol:
 
« Last Edit: May 14, 2010, 12:52:52 pm by YZMSQ »

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #5 on: May 14, 2010, 01:45:20 pm »
Hi,now I can compile it using "g++ naoxi.cpp -mwindows" successfully(the option -mwindows really makes differences ) from command line in cmd.exe,however,I still fail to build it even if "-mwindows"has been given.Do I do anything wrong? :P

build log:

Code: [Select]
mingw32-g++.exe -march=i686 -fexec-charset=GBK -mwindows    -c "C:\Documents and Settings\Administrator\naoxi.cpp" -o "C:\Documents and Settings\Administrator\naoxi.o"
mingw32-g++.exe  -o "C:\Documents and Settings\Administrator\naoxi.exe" "C:\Documents and Settings\Administrator\naoxi.o"  
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x8f): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x226): undefined reference to `[email protected]'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x23b): undefined reference to `[email protected]'
« Last Edit: May 14, 2010, 01:50:12 pm by YZMSQ »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #6 on: May 14, 2010, 01:50:58 pm »
Are you sure you have only one MinGW installation in your system ?
If not it can make a difference.

You use g++.exe on commandline and mingw32-g++.exe inside C::B, that should be the same files (or more exactly one is a copy of the other), please make sure, that this is the case.

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #7 on: May 14, 2010, 02:04:26 pm »
As you know,I installed the C::B with mingw included at first,and later,I installed TDM as you introduced in C:\MinGW :)   In addition,I changed the "compiler's installation directory"in [compiler and debugger] to C:\MinGW.I also added "-mwindows" and "-fexec-charset=GBK"in "compiler settings"->"other options".  That's all what I did. :D
So,did I do anything unreasonable? :(

Offline YZMSQ

  • Single posting newcomer
  • *
  • Posts: 6
Re: I could compile it in MS VC++6.0 while failed in codeblocks
« Reply #8 on: May 15, 2010, 05:09:20 am »
Hi,there:
It's solved.Adding "-mwindows" in [Global compile settings]->[linker settings]->[other linker options] will make great differences. :D
Thank you for your selfless help. :D