undefined reference to `WinMain' [duplicate] - c++

This question already has answers here:
undefined reference to `WinMain#16'
(7 answers)
Closed 6 years ago.
I am taking a course in c++ and I've copied the code and done exactly the same as the tutor in the course did in the lecture, however when I do so I get a long error "...undefined reference to `WinMain'" and I don't know what to do.
I am using Eclipse Neon on Windows 10 (and Cygwin, I don't know if it's relevant) and this is my code:
`
#include <iostream>
#include <SDL.h>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
`
The code works and runs without the "#include ", but when I add this line of code the error pops up when I run it (so I guess that's where the problem is). When the tutor in the course run this code it works and prints out the text correctly.
Can someone please tell me how I get rid of this error and get this simple program to run?

https://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
I get "Undefined reference to 'WinMain#16'"
Under Visual C++, you need to link with SDL2main.lib. Under the gcc
build environments including Dev-C++, you need to link with the output
of "sdl-config --libs", which is usually: -lmingw32 -lSDL2main -lSDL2
-mwindows

Related

C++ - Undefined reference to octomap::OcTree::OcTree(double)' [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 9 months ago.
I'm trying to use the library octomap and have installed according to the instructions in their GitHub. However, when I try to build and run this simple code with VSCode build task (with g++) I get the error: undefined reference to `octomap::OcTree::OcTree(double)' and other undefined references to Octomap related code. VSCode recognizes that the library is installed (it suggests it when I type #include <...> ) and gives me more information about the octomap functions when I hover over them.
#include <iostream>
#include <octomap/octomap.h>
#include <octomap/OcTree.h>
using namespace std;
int main()
{
octomap::OcTree tree(0.1);
cout << "Hello, World!! \n";
return 0;
}
Octomap header files are in /usr/local/lib/octomap/octomap/include/octomap from what I can tell. I haven't coded with C++ a lot, so this might be just a newbie mistake that I'm missing. I've tried several approaches but still can't get it to work. What am I missing here?
Thanks in advance.
your problem is the program wasn't linked with octomap library
use cmake and include some lines like:
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})
or from command line with g++ <source files> -loctomap -loctomath
refer : http://wiki.ros.org/octomap

Compiling multiple files in Visual Studio Code resulting in error

I'm relatively new to coding in C++ and have started working with main and header files and I've created a program to test it out, however, the following program results in the following compiler error:
Undefined symbols for architecture x86_64:
"Print()", referenced from:
_main in test-7d0225.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is my current code.
test.cpp
#include <iostream>
#include "test.h"
using namespace std;
int main() {
Print();
return 0;
}
test.h
#ifndef TEST_H
#define TEST_H
void Print();
#endif
test1.cpp
#include <iostream>
#include "test.h"
using namespace std;
void Print() {
cout << "Hello" << endl;
}
Nothing I've found online has helped me and my only assumptions are that my compiler isn't set up correctly. I've tried compiling both of these of files by typing in "g++ test.cpp test1.cpp", as well, but yields similar results. I would like to note that I am on Mac as well. Please feel free to leave any comments or suggestions for how I've asked this question, this is my first time on stack overflow.
Your code seems just fine, I’ll will try to compile it on vscode myself.
One problem could be your vscode launch.json. I have had the same problem as what I am describing. Vscode can be quite “Finicky” with low level languages like c and c++. In your launch file (or tasks file if it calls something in tasks) make sure you compile *.cpp files in the folder. I would look something like {folder}/**.cpp. To find the exact command look on vscode’s official site.
Given that you tried compiling your code outside of vscode and assuming that everything is in the same folder, it might be a coding problem. Again, your code looks fine. Go online and find some learning to code website with multiple file coding. Copy their code and do the same thing that you did with your code. If it doesn’t work there is definitely a problem with how to code is being compiled. Otherwise revise your code and compare to find the problem.
Also, could you provide the terminal command vscode prints (I am also on Mac). It will be in the terminal tab in the g++ section, not in bash)
P.S. I am also new to stack overflow so any suggestions you have for me will be great.

Mingw and c++ vectors [duplicate]

This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
I am writing a simple small program in c++ to test vectors. The following code works well and output hello to the cmd.
The steps I follow are:
g++ filename.cpp to compile
.\a.exe to run
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout<<"hello";
return 0;
}
However, when I declare a vector, the hello does not show and the program seem to not working at all.
#include <iostream>
#include <vector>
using namespace std;
vector<int> a;
int main()
{
cout<<"hello";
return 0;
}
I do not get any error message while compiling. But I do get a certain message about no entry point when I run outside the cmd.
The procedure entry point _ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv
could not be located in the dynamic link library
I searched on google and stack overflow but could not find a solution to my problem.
For anyone who would read this later on, I had something called gtk installed and defined in the environment path variables and it seems like it was colliding with MinGW. Everything runs smooth by writing:
g++ ex1.cpp -static-libgcc -static -static-libstdc++
The problem is likely caused by the fact that the DLL containing the function the program is trying to access (_ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv here) is not found by Windows when it tries to execute your program.
There are a few solutions for this :
Static linking with the C++ library (--static-libstdc++) (this will directly link the C++ library into your executable (this may make your program bigger))
Putting the libstdc++ dll in your program folder (you should be able to find it somewhere in the compiler install folder)
Adding the path to the libstdc++ dll to the global PATH variable (If you want to know more about adding to the PATH, see here) so that the dll will be found for any executable running on your computer
Doing any of these should fix your problem.

Using std::string causes Windows "Entry Point Not Found" [duplicate]

This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
When I compile this with G.C.C.:
#include <iostream>
#include <string>
int main()
{
std::cout << std::string("\r\n");
return 0;
}
By using the following batch:
g++ -Wall main.cc
And attempt executing the output (a.exe), then Windows crashes the initialization with this error:
If I avoid using std::string in the C++ code it executes normally, even including <string>. Any ideas?
Note, first time testing std::string.
I run Windows 8 / 64 bits. My compiler includes this file build-info.txt:
# **************************************************************************
version : MinGW-W64-builds-4.3.0
user : nixman
date : 03.30.2017- 1:01:08 PM
args : --mode=gcc-6.3.0 --buildroot=/c/mingw630 --jobs=2 --rev=2 --threads=win32 --exceptions=sjlj --arch=i686 --bin-compress
[much more here...]
# **************************************************************************
Also note that I'm used to disable and uninstall all possible anti-virus utilities (e.g., Windows Defender).
It was hard to find a solution (zZZzzZzZzZz), but finally, it's on this answer.
g++ -Wall -D_GLIBCXX_USE_CXX11_ABI=0 main.cc

undefined reference to `WinMain#16' with a main [duplicate]

This question already has answers here:
undefined reference to `WinMain#16'
(7 answers)
Closed 8 years ago.
I have a really simple shell of of a program. The editor i use is Scite and my compiler is MingW.
The answer to this is that I'm missing a main but i do have a main().
Main.cpp
#include <iostream>
#include "Money.h"
using namespace std;
int main()
{
}
Money.cpp
#include "Money.h"
#include <iostream>
using namespace std;
Money::Money()
{
cout << "test"
}
Money.h
#ifndef MONEY_H
#define MONEY_H
class Money
{
public:
Money();
private:
};
#endif //MONEY_H
Everytime I try to compile Money.cpp it gives me the error
libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain#16'
And I'm not sure what's wrong with the program. All the files are in the same directory. I'm fairly new to programming in C++ so if you can give me a very basic answer or fix it be greatly appreciated.
WinMain is the entry point of Windows "Win32" programs.
You are probably using Visual Studio wizard to create your C++ project, but you chose a Windows C++ application. Such an application is expected to have WinMain() as an entry point (the #16 part is name mangling decorations, according to Visual C++ compiler rules), but you haven't provided that in your code.
If you want to build a C++ console-mode application (with the classical standard main() entry point), you may want to choose the Win32 Console Application option when creating a new project with Visual Studio.
E.g. this is a screenshot from Visual Studio 2010: