'tcc: error: undefined symbol '_GetConsoleWindow@0'
I'm making a program in C/C++ which must run hidden using this code:
#define _WIN32_WINNT 0x0500
#include <windows.h>
int main(){
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
. . .
}
I really want to use tinyc to compile it because it's much better than gcc (almost, the final executable is much tiny than gcc).
The point is that when I try to compile it using:
tcc PROGRAM.c -luser32
It makes an error which says:
tcc: error: undefined symbol '_GetConsoleWindow@0'
But when I use gcc it works! I think I have a missed library but I don't know which one.
Please, some help :)
Solution 1:[1]
According to MSDN, GetConsoleWindow
is located in Kernel32.dll
Try:
tcc PROGRAM.c -luser32 -lkernel32
EDIT:
tcc's kernel32.def
is missing the export for GetConsoleWindow
.
Append the string GetConsoleWindow at the end of the def file located in the lib
directory inside tcc's installation folder.
Solution 2:[2]
remove gdi32.def kernel32.def msvcrt.def user32.def
files from C:\tcc\lib
; remove all .def
files from C:\tcc\lib
#include <windows.h>
#include <wincon.h>
#include <stdio.h>
#include <conio.h>
void main()
{
HWND hwnd;
hwnd = GetConsoleWindow();
HDC hdc;
hdc = GetWindowDC(hwnd);
printf("console hwnd: %p\n", hwnd);
printf("console hdc: %p\n", hdc);
HPEN hPenNull, hPenBlack, hPenRed, hPenGreen, hPenBlue;
hPenNull=GetStockObject(NULL_PEN);
hPenBlack=CreatePen(PS_SOLID, 2, RGB(0,0,0));
hPenRed=CreatePen(PS_SOLID, 2, RGB(255,0,0));
hPenGreen=CreatePen(PS_SOLID, 2, RGB(0,255,0));
hPenBlue=CreatePen(PS_SOLID, 2, RGB(0,0,255));
HBRUSH hBrushNull, hBrushBlack, hBrushRed, hBrushGreen, hBrushBlue, hBrushYellow;
hBrushNull=GetStockObject(NULL_BRUSH);
hBrushBlack=CreateSolidBrush(RGB(0,0,0));
hBrushRed=CreateSolidBrush(RGB(255,0,0));
hBrushYellow=CreateSolidBrush(RGB(255,255,0));
hBrushGreen=CreateSolidBrush(RGB(0,255,0));
hBrushBlue=CreateSolidBrush(RGB(0,0,255));
SelectObject(hdc, hPenRed);
SelectObject(hdc, hBrushYellow);
Ellipse(hdc, 200,50,260,150);
SelectObject(hdc, hPenNull);
SelectObject(hdc, hBrushRed);
Ellipse(hdc, 140, 80, 180, 120);
SelectObject(hdc, hPenBlue);
SelectObject(hdc, hBrushNull);
Ellipse(hdc, 280, 50, 340, 150);
getch();
}
-L"C:\tcc\lib" -lkernel32 -luser32 -lgdi32 -Wl,-subsystem=console
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |