Code::Blocks Forums

User forums => Help => Topic started by: Дмитро on October 18, 2019, 08:03:08 pm

Title: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 08:03:08 pm
Hello Hello everyone! My codeblocks gave the error. undefined reference to `GetStockObject@4'| What is it? How to solve it, what to do to fix it? :'(

Code: mysql
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Miguel Gimenez on October 18, 2019, 08:24:49 pm
You must link with Gdi32.lib (or libGdi32.a if using MinGW).

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 08:38:54 pm
Yes, I find in myself really. D:\CodeBlocks\MinGW\lib\libgdi32.a
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 09:22:59 pm
I am running Code::Blocks version 17ю12 on windows
(version 7). The compiler I use is MinGW
version 5.1.0.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 09:28:53 pm
What settings kodeblocksiv should be performed to correctly find libgdi32.a? How is it before, for years, I have not met the problem of finding ordinary libraries?
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 09:33:57 pm
||error: :\CodeBlocks\MinGW\lib: Invalid argument|
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 18, 2019, 09:37:14 pm
ld.exe||cannot find D:\CodeBlocks\MinGW\lib: Permission denied|
Title: Re: undefined reference to `GetStockObject@4'|
Post by: stahta01 on October 18, 2019, 09:58:59 pm
You must link with Gdi32.lib (or libGdi32.a if using MinGW).

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)

Post a full rebuild log if you still need help.

Tim S.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 19, 2019, 09:37:44 am
Yes, I am still unable to resolve this issue, unable to understand where there are troubles.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 19, 2019, 09:47:06 am
Have I provided all the necessary information and information?
Title: Re: undefined reference to `GetStockObject@4'|
Post by: BlueHazzard on October 19, 2019, 11:29:37 am
What is in "D:\CodeBlocks\MinGW\lib"?
have you added it by yourself?
Title: Re: undefined reference to `GetStockObject@4'|
Post by: stahta01 on October 19, 2019, 06:07:27 pm
Do not tell the linker to look for libraries in a folder that does not exist!

Code
mingw32-g++.exe -LG:\SDL\SDL-devel-1.2.15-mingw32\SDL-1.2.15\lib -LG:\SDK\Lib -LD:\CodeBlocks\MinGW\lib -o bin\Debug\WindowMain_0.exe obj\Debug\WindowMain_0.o -lmingw32 -lSDLmain -lSDL D:\CodeBlocks\MinGW\lib

Edit: If the folder does exist, then remove the folder from the "other linker options".

Tim S.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 20, 2019, 12:02:18 pm
No, it's still not clear to me how to fix the error.

Actually, the one needed on the computer was originally, is, and has its own address D: \ CodeBlocks \ MinGW \ lib inside this folder.
Also, there are many other libs, for example libvideoprt.a, and so on, about 144 libs.

For a long time, actually years earlier, I did not carefully consider this.
Added only other third-party inclusions and libs.

In addition, there are also D: \ CodeBlocks \ MinGW \ bin paths, inside which there are compilers and some many dlls.
And there is also a path and a folder D: \ CodeBlocks \ MinGW \ include, with various inclusions inside it, and in it there are subfolders
D: \ CodeBlocks \ MinGW \ include \ GL, D: \ CodeBlocks \ MinGW \ include \ sys, D: \ CodeBlocks \ MinGW \ include \ gdiplus, D: \ CodeBlocks \ MinGW \ include \ ddk also containing inclusions too.

Also along the path D: \ CodeBlocks \ MinGW \ libexec \ gcc \ mingw32 \ 5.1.0 also with programs and containing dll and for example collect2.exe, and deeper inside this folder there is also a folder D: \ CodeBlocks \ MinGW \ libexec \ gcc \ mingw32 \ 5.1.0 \ install-tools containing fixincl.exe and files.
Also along the path D: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 there are many .a libraries, among them, for example, libatomic.a, one file libstdc .dll.a-gdb.py, several .o, inside this folder also contains the folder D: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include containing a lot of .h files, for example avx512bwintrin.h, and inside it the folder D: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c, which also contains many folders, many files, and many complex nesting levels inside.
Here inside
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ tr2 \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ tr1 \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ profile \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ parallel \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ mingw32 \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ ext \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ experimental \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ decimal \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ debug \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ bits \
d: \ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 5.1.0 \ include \ c \ backward \

Still everywhere around and inside and also in the depths and everywhere there are many and especially many folders, subfolders and everywhere there are many complicated folders and paths.
I'm reviewing and studying at this moment, I was a little surprised at the many complexity of the structure of subfolders.



And now, of course, I want to configure my codeblocks always so that it works always correctly and has a good one.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 20, 2019, 12:07:26 pm
In short, all the specified folders are there, the paths are correct. There is a necessary lib. I can’t, I don’t know how to set the correct settings for codeblocks. His work as a whole suits me, except for the moment indicated in the title of the topic.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: gd_on on October 20, 2019, 12:27:49 pm
as told by stahta01 the problem comes certainly from this :
Code
mingw32-g++.exe -LG:\SDL\SDL-devel-1.2.15-mingw32\SDL-1.2.15\lib -LG:\SDK\Lib -LD:\CodeBlocks\MinGW\lib -o bin\Debug\WindowMain_0.exe obj\Debug\WindowMain_0.o -lmingw32 -lSDLmain -lSDL D:\CodeBlocks\MinGW\lib

you set D:\CodeBlocks\MinGW\lib twice.

the first -LD:\CodeBlocks\MinGW\lib tell the linker where to find some libraries (-L option). This is probably good.
but the last one D:\CodeBlocks\MinGW\lib is certainly wrong. You have probably introduced this somewhere in your settings (other settings probably). Delete that wrong setting.

gd_on
Title: Re: undefined reference to `GetStockObject@4'|
Post by: BlueHazzard on October 20, 2019, 12:30:45 pm
The linker thinks "D:\CodeBlocks\MinGW\lib" is a library, but it is not. It is a folder.
You have to add the folder where the libraries are in
Project->Build options->Search directories->Linker
and the libraries only with name in 
Project->Build options->Search directories->Linker settings->Link libraries

Do not add any library settings in "Project->Build options->Search directories->Linker settings->Other linker options"
or if you do keep atention that "-L" is for folders and "-l" is for libraries

in the line posted by stahta01:
Code
mingw32-g++.exe -LG:\SDL\SDL-devel-1.2.15-mingw32\SDL-1.2.15\lib -LG:\SDK\Lib -LD:\CodeBlocks\MinGW\lib -o bin\Debug\WindowMain_0.exe obj\Debug\WindowMain_0.o -lmingw32 -lSDLmain -lSDL D:\CodeBlocks\MinGW\lib
You can see that
Code
 D:\CodeBlocks\MinGW\lib
has no option prefix ("-L" or "-l") so you have posted this in one place where you should not...

[Edit:] ok, someone was quicker, but i post it anyway
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 20, 2019, 01:25:24 pm
Yes Yes. Of course, I deleted it. Thank! But I get an undefined reference error to `GetStockObject @ 4 '|. I experimented with the settings for about half an hour, and did not succeed in compiling.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 20, 2019, 01:26:55 pm
I am still carefully reading the answers, I have not seen the latter, and I will try.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: oBFusCATed on October 20, 2019, 01:36:55 pm
Go to this page: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getstockobject
Scroll to the bottom, read the "Requirements", add the required libraries to your linker settings.
Title: Re: undefined reference to `GetStockObject@4'|
Post by: Дмитро on October 20, 2019, 08:20:45 pm
Yes, I compiled it!! Hurray!! Helped understand the last message.(no last, Posts: 2502)
In general, thank you all very much.
My settings:
Project->Build options->Linker settings->Link libraries    libgdi32.a
Project->Build options->Search directories->Linker   D:\CodeBlocks\MinGW\lib


Title: Re: undefined reference to `GetStockObject@4'|
Post by: oBFusCATed on October 21, 2019, 03:15:41 am
Project->Build options->Linker settings->Link libraries    libgdi32.a
This should be just gdi32!