undefined reference to `WinMain#16' when running cpp program [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
undefined reference to `WinMain#16'
(7 answers)
I cannot figure out the "undefined reference to Winmain#16 error"
(1 answer)
Closed 2 years ago.
Im installed mingw and vs code on my system , i followed all the steps,added to environment variable and all but when im running simple hello world program it gives this error:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
My code :
#include<iostream
using namespace std;
int main(){
cout<<"Hello World"<<endl;
return 0;
}

Related

Why is function reference still unresolved when link library was found? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 5 months ago.
I am trying to implement my own thumbnail provider by following Microsoft's thumbnail provider code sample. The code has been coming together nicely, but now I needed to figure out a way to compile (on Windows). MSYS2 appears to be a popular option.
g++ -shared -o GrmgThumbnailProvider.dll -lshlwapi -lgdi32 Dll.cpp GrmgThumbnailProvider.cpp
This causes errors:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\cc5HnXOH.o:Dll.cpp:(.text$_ZN13CClassFactory14QueryInterfaceERK5_GUIDPPv[_ZN13CClassFactory14QueryInterfaceERK5_GUIDPPv]+0x31): undefined reference to `QISearch'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\ccXzQLhd.o:GrmgThumbnailProvider.cpp:(.text+0x36f): undefined reference to `__imp_CreateDIBSection'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Zyl\AppData\Local\Temp\ccXzQLhd.o:GrmgThumbnailProvider.cpp:(.text$_ZN18CGrmgThumbProvider14QueryInterfaceERK5_GUIDPPv[_ZN18CGrmgThumbProvider14QueryInterfaceERK5_GUIDPPv]+0x31): undefined reference to `QISearch'
collect2.exe: error: ld returned 1 exit status
The libraries are definitely found: g++ complains if I change the library names in the -l argument to some nonsense. How is it these references cannot be resolved despite the required libraries being both present and found?
QISearch
CreateDIBSection

C++ Compiler Error when trying to link two files together [duplicate]

This question already has answers here:
undefined reference to main for shared library
(1 answer)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
I am justing wondering what the error means here if anyone can help me.
g++ -o Try2 student.o studentlist.o
Undefined first referenced
symbol in file
main /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.4/crt1.o
ld: fatal: Symbol referencing errors. No output written to Try2
collect2: error: ld returned 1 exit status

Undefined Reference-ld returned 1 exit status [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Using G++ to compile multiple .cpp and .h files
(13 answers)
Closed 3 years ago.
I am new to c++ and was working with OOP concepts.
I created a header file(account.h), a method definition file(account.cpp) and a main file(ex2.cpp).
When, I am compiling the main file, I am getting an error as "undefined reference to".
The detailed error is:-/tmp/ccps76QE.o: In function `main':
ex2.cpp:(.text+0x8d): undefined reference to `Account::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, double)'
ex2.cpp:(.text+0xb7): undefined reference to `Account::display()'
ex2.cpp:(.text+0xd6): undefined reference to `Account::display()'
ex2.cpp:(.text+0x134): undefined reference to `Account::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, double)'
ex2.cpp:(.text+0x15e): undefined reference to `Account::display()'
ex2.cpp:(.text+0x178): undefined reference to `Account::display()'
.
Kindly help me regarding this issue as I am new to programming and c++

How to build my first OpenGL program [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
I am having trouble making a simple OpenGL program.
I did some research and found to make OpenGL programs I'll need
SFML - For creating window
GLEW - For extension handling
I have been using SFML for a while, it works fine. Following the official SFML page, and adding an additional linker option: -l opengl32 I managed to compile the typical OpenGL-with-SFML code shown Here.
So i moved on to make OpenGL applications, but i couldn't compile any of the tutorials on the net, due to undefinied references even after setting up GLEW. Now i have this piece of code taken from the least appreciated answer from here. I have followed the instructions from that post, but still getting errors:
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c|| undefined reference to `wglGetProcAddress#4'
I am using
Windows 10
Codeblocks 16.1
Default MinGW packed with codeblocks
(SFML, GLEW)
**Edit:**
My full Build log:
-------------- Build: Debug in opengl_minus1 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -LC:\prog\SFML\2.3.2\lib -LC:\prog\GLEW\1.13\lib -o bin\Debug\opengl_minus1.exe obj\Debug\main.o -l opengl32 C:\prog\SFML\2.3.2\lib\libsfml-graphics.a C:\prog\SFML\2.3.2\lib\libsfml-window.a C:\prog\SFML\2.3.2\lib\libsfml-system.a C:\prog\GLEW\1.13\lib\libglew32.a
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x29c): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2b8): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2d4): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2e8): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2fc): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x310): more undefined references to `wglGetProcAddress#4' follow
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1786c): undefined reference to `glGetString#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x178bf): undefined reference to `wglGetCurrentDC#0'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1792f): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17943): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1795e): undefined reference to `wglGetCurrentDC#0'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x179da): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b60): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b7c): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b9a): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17f7c): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17f98): more undefined references to `wglGetProcAddress#4' follow
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19def): undefined reference to `glGetString#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19f40): undefined reference to `glGetString#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19f85): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fa1): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fbd): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fd6): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1a08f): undefined reference to `wglGetProcAddress#4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1a0ab): more undefined references to `wglGetProcAddress#4' follow
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj): bad reloc address 0x13a98 in section `.rdata'
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
26 error(s), 0 warning(s) (0 minute(s), 0 second(s))
The undefined reference to wglGetProcAddress occurs in member glew.obj of library libglew32
The function wglGetProcAddress is defined in libopengl32 but is not linked because the
linkage order of the libraries is the wrong way round.
In the linkage sequence, files that need symbol definitions must occur before the ones the provide the definitions,
because the linker will only link an object module from a library if it provides
a definition of at least one symbol that is already referenced in the linkage, but not yet defined.
So link -lopengl32 after libglew32.a

Is there a default path to library in ubuntu? [duplicate]

This question already has an answer here:
g++ and boost linker error on Ubuntu oneiric
(1 answer)
Closed 8 years ago.
folks!
I'm using ubuntu 12.04 and trying to compile a boost test program. I installed boost with
sudo apt-get install libboost-all-dev
an so, I don't know where i can find my libraries. I tried do compile that using
g++ -lboost_system -lboost_thread boost_test.cpp
thinking maybe to have some default path where ubuntu installed boost automatically, but it was wrong and I had the following:
/tmp/ccTKXzTR.o: In function
__static_initialization_and_destruction_0(int, int)':
boost_test.cpp:(.text+0xcc): undefined reference to
boost::system::generic_category()' boost_test.cpp:(.text+0xd8):
undefined reference to boost::system::generic_category()'
boost_test.cpp:(.text+0xe4): undefined reference to
boost::system::system_category()' /tmp/ccTKXzTR.o: In function
boost::system::error_code::error_code()':
boost_test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::error::get_system_category()':
boost_test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
boost_test.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[_ZN5boost4asio6detail20posix_tss_ptr_createERj]+0x19):
undefined reference topthread_key_create' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service,
boost::asio::detail::task_io_service::thread_info>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED5Ev]+0x15): undefined reference topthread_key_delete' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl,
unsigned char>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED5Ev]+0x15):
undefined reference topthread_key_delete' collect2: error: ld
returned 1 exit status
Can someone help-me to figure out if my library is correctly installed and compile that?
I found out /usr/include/boost is the path to boost headers and /usr/lib contains all boost libraries i want to.