SDL2 Windows undefined reference to `WinMain#16' with Eclipse [duplicate] - c++

This question already has answers here:
undefined reference to WinMain#16 C++, SDL-2
(2 answers)
undefined reference to `WinMain#16'
(7 answers)
Closed 2 years ago.
I have this snippet of code:
#include <SDL2/SDL.h>
#include <iostream>
int main(int argc, char* argv[]) {
std::cout << "!!!Hello World!!!" << std::endl;
return 0;
}
The error reported is this:
Info: Internal Builder is used for build g++ -o
cavestory-developement.exe "src\cavestory-developement.o" -lmingw32
-lSDL2main -lSDL2 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
17:13:45 Build Failed. 1 errors, 0 warnings. (took 205ms)
Any help solving this problem would be greatly appreciated.

Related

compiling sdl simple program in dev C++ shows undefined reference to `WinMain' [duplicate]

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)
Closed 2 years ago.
My version of DEV C++ is 5.11 and I have used version SDL2-2.0.12 and OS is Windows 10.
Folder path of sdl.h file is C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\include\SDL2
I have done my project settings as shown in ::
https://thenumbat.github.io/cpp-course/sdl2/01/devSetup.html#:~:text=Open%20up%20your%20project%20and,and%20select%20the%20lib%20folder.
My program
#include <iostream>
#include "SDL.h"
using namespace std;
int main( int argc, char* args[] )
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
cout << "SDL init failed.\n";
return 1;
}
SDL_Quit();
return 0;
}
While compiling I am getting such message::
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o) In function `main':
C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain'
------ this is in red color ---------
C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\collect2.exe [Error] ld returned 1 exit status
C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\Makefile.win recipe for target 'SDLproj1.exe' failed
Please see the attached image.

How to link giflib? [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 2 years ago.
Unfortunately, I couldn't find any beginner friendly tutorial on how to use giflib.
This is my code:
#include <iostream>
#include <gif_lib.h>
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cerr << "No argument" << std::endl;
return 1;
}
GifFileType *gifFile = DGifOpenFileName(argv[1], NULL);
DGifSlurp(gifFile);
}
I try to compile it like this:
g++ main.cpp
but it yields this error:
/usr/bin/ld: /tmp/ccd5G2QR.o: in function `main':
main.cpp:(.text+0x5c): undefined reference to `DGifOpenFileName'
/usr/bin/ld: main.cpp:(.text+0x6c): undefined reference to `DGifSlurp'
collect2: error: ld returned 1 exit status
I'm on Ubuntu 20.04 and I've installed the libgif-dev package.
How to link the giflib library for the functions to work?
Trying randomly around I found it's:
g++ main.cpp -lgif

collect2: error: 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)
Closed 8 years ago.
I used the following:
gcc -c -O4 ab_test.c
This worked and generated ab_test.o without error, but
gcc -o ab_test ab_test.o -lgsl -lgslcblas -lm
lead to error as:
**/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crt1.o: In function `_start':
/home/abuild/rpmbuild/BUILD/glibc-2.18/csu/../sysdeps/x86_64/start.S:118: undefined reference to `main'
collect2: error: ld returned 1 exit status**
The code is ab_test.c is as under
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
Main()
{
int i, temp_int;
char amode[30];
char bmode[30];
float wave_vector_y;
for(i=0; i<41; i++)
{
//// set wave vector ////
wave_vector_y = i*0.005;
temp_int = 10000*wave_vector_y;
sprintf(amode,"a%04d.dat",temp_int);
sprintf(bmode,"b%04d.dat",temp_int);
}
}
Your "main" signature should be something like int main(void)or int main(int argc ,char *argv[]) and not old C style syntax for int Main().

gcc Linker and OGDF "undefined reference to `ogdf::Initialization::Initialization()'"

I am trying to get OGDF working to see if it is suitable for my project, but I am having trouble with a sample program.
I am trying to compile this example program:
#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;
int main()
{
Graph G;
randomSimpleGraph(G, 10, 20);
DfsAcyclicSubgraph DAS;
DAS.callAndReverse(G);
G.writeGML("test.gml");
return 0;
}
using this command:
$g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ -lOGDF test2.cpp
But I get the following error
/tmp/ccbpkfdt.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `ogdf::Graph::Graph()'
test2.cpp:(.text+0x2e): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test2.cpp:(.text+0x4e): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test2.cpp:(.text+0x62): undefined reference to `ogdf::Graph::writeGML(char const*) const'
test2.cpp:(.text+0x7f): undefined reference to `ogdf::Graph::~Graph()'
test2.cpp:(.text+0xa1): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccbpkfdt.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0xfb): undefined reference to `ogdf::Initialization::Initialization()'
test2.cpp:(.text+0x112): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x16): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0xb): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: error: ld returned 1 exit status
I tried compiling hello world, with an include from OGDF, and I still got:
undefined reference to `ogdf::Initialization::Initialization()'
I think I am not linking properly or something?
You have to be very careful in which order you type stuff when linking with a library.
Try putting test2.cpp before -lOGDF instead, like this:
g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ test2.cpp -lOGDF
You must build your program using the -DOGDF_DLL when using OGDF as a shared library.
See here: http://www.ogdf.net/doku.php/tech:defines

Nasty error when initializing vector

I am just trying to make a vector, but it gives me a huge error and I am following a working example from my other project. The code:
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
struct organism {
bool One;
bool Two;
};
std::vector<organism> organisms;
int main() {
printf("Content-type: text/html\n\n");
printf("TEST");
printf(getenv("QUERY_STRING"));
return 0;
}
The error:
> "make"
C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.text$_ZN9__gnu_cxx13new_allocatorI8organismE10deallocateEPS1_j[__gnu_cxx::new_allocator<organism>::deallocate(organism*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.eh_frame$_ZNSt12_Vector_baseI8organismSaIS0_EED2Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.eh_frame$_ZNSt6vectorI8organismSaIS0_EED1Ev+0x13): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
"make": *** [build] Error 1
> Process Exit Code: 2
> Time Taken: 00:01
I can compile it if I comment out std::vector<organism> organisms; but I have no clue what's wrong with that line. It's exactly the same in my other project, which compiles fine.
You need to compile with g++.exe instead of gcc.exe so that it will know it needs to link with the C++ library.