User forums > Using Code::Blocks
[Fixed]I could compile it in MS VC++6.0 while failed in codeblocks
YZMSQ:
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: ---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)锛氬鈥楪etStockObject@4鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x229)锛氬鈥楽etTextColor@8鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x23e)锛氬鈥楪etTextMetricsA@8鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x2c6)锛氬鈥楥reateFontA@56鈥欐湭瀹氫箟鐨勫紩鐢uments and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x311)锛氬鈥楾extOutA@20鈥欐湭瀹氫箟鐨勫紩鐢t2:ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings
--- End code ---
And my source file(naoxi.cpp):
--- Code: ---#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;
}
--- End code ---
So what's wrong with this?Could you help me,Please? :(
P.S.:I use windows xp sp2.
Jenna:
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.
YZMSQ:
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:
Jenna:
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.
YZMSQ:
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: ---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 `_GetStockObject@4'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x36d): undefined reference to `_SetTextColor@8'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x385): undefined reference to `_GetTextMetricsA@8'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x414): undefined reference to `_CreateFontA@56'
C:\Documents and Settings\Administrator\naoxi.o:naoxi.cpp:(.text+0x47a): undefined reference to `_TextOutA@20'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
5 errors, 0 warnings
--- End code ---
Still failed.I am not clear about the"undefined reference"~~~ :o
BTW,I haven't used a path with chinese-characters. :lol:
Navigation
[0] Message Index
[#] Next page
Go to full version