User forums > Using Code::Blocks
Linking Kernel32.DLL
(1/1)
lmsmi1:
I have a project that needs to be linked to Kernel32.dll. For some reason, even after I link libkernel32.a in "Build Options" < "Linker" it still gives me the same errors. Here's the project code:
--- Code: ---#include <windows.h>
#include <string>
#include "resource.h"
using namespace std;
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HINSTANCE hInstance;
HWND Label1;
HANDLE Label1Handle;
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) {
MSG msg;
WNDCLASS wc;
HWND hwnd = NULL;
hInstance = hThisInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = CreateSolidBrush(RGB(241, 241, 241));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MAIN_ICON));
wc.hInstance = hThisInstance;
wc.lpfnWndProc = WinProc;
wc.lpszClassName = "Window";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc)) {
MessageBox(NULL, "Error registering class", "ERROR", MB_OK);
return 0;
}
hwnd = CreateWindow("Window",
"Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
400,
NULL,
NULL,
hThisInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE: {
string LabelText1 = "Hello";
Label1 = CreateWindowEx(0,
"STATIC",
"Some static text",
WS_CHILD | WS_VISIBLE,
25,
125,
150,
20,
hwnd,
(HMENU)static_1,
hInstance,
0);
SendDlgItemMessage(hwnd, static_1, WM_SETFONT, (WPARAM)CreateFont(12, 10, 0, 0, 500, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, TEXT("Terminal")), MAKELPARAM(TRUE, 0));
} break;
case WM_DESTROY: {
PostQuitMessage(0);
return 0;
} break;
case WM_CLOSE: {
DestroyWindow(hwnd);
} break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
--- End code ---
Here's the project error list:
--- Code: ---..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `LeaveCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `DeleteCriticalSection@4'|
..\..\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `InitializeCriticalSection@4'|
||=== Build finished: 9 errors, 0 warnings ===|
--- End code ---
stahta01:
You likely made a mistake; look at the full compiler log. See if something is wrong or missing.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
FYI: In linking the order of the object file(s) and libraries matter.
Tim S.
comsytec:
To me this obviously happens when when I forgot to rename c:\MinGW\lib to e.g. c:\MinGW\libX
This is while linker looks for startup files and libraries first in c:\MinGW\lib - some built in feature of the linker
I havent tried this on system where mingw is not installed
This is my simple but stupid method of quick fix
MortenMacFly:
...why not start like this:
http://lmgtfy.com/?q=undefined+reference+to+LeaveCriticalSection
?
Navigation
[0] Message Index
Go to full version