Discussion:
[Mingw-users] Undefined reference to WinMain@16
C. Marcano
2010-01-06 00:11:38 UTC
Permalink
Hi, everybody:
I am just starting to use cygwin/gcc/mingw environment. So, I am
a novice.
I am tryng to compile a simple C++ program, with g++. It compiles
without error, but when I try to 'g++ -o test test.o', the linker reports:
"Undefined reference to ***@16"

Searchinf for a solution in Internet, I have found some explanations,
saying that this problem has to do with linking different modules of
a projects in environments as Visual C++. Other say that it has
to do with the redirection of I/O in Windows But I didn't find
the solution to the case of being using gcc/mingw.

Trying to solve this error, I have found that linking with
-lmingw32 -lSDLMain -mwindows can work. I tried to do this,
but the linker said "ld: cannot find -lmingw32", I reinstalled
mingw isong cygwin-setup, but the same error still reports.
Also, I have tested linking qith the library libmingw32.a, which
didn't solve the problem either.

Could you tell me, please, what could be happening or refer to sites
containing the solution?
Greg Chicares
2010-01-06 00:48:17 UTC
Permalink
Post by C. Marcano
I am tryng to compile a simple C++ program, with g++. It compiles
Searchinf for a solution in Internet, I have found some explanations,
saying that this problem has to do with linking different modules of
a projects in environments as Visual C++. Other say that it has
to do with the redirection of I/O in Windows But I didn't find
the solution to the case of being using gcc/mingw.
I don't think those explanations are applicable. Here is a useful way
to search the MinGW mailing-list archives:

http://search.gmane.org/?query=Undefined+reference+to+WinMain%4016&group=gmane.comp.gnu.mingw*
Post by C. Marcano
Trying to solve this error, I have found that linking with
-lmingw32 -lSDLMain -mwindows can work. I tried to do this,
but the linker said "ld: cannot find -lmingw32", I reinstalled
mingw isong cygwin-setup, but the same error still reports.
Also, I have tested linking qith the library libmingw32.a, which
didn't solve the problem either.
Do you actually want to use libsdl, or is this just a random idea
that you found on some web page? If you do want to use libsdl, then
g++ -o test test.o
seems incorrect because it doesn't mention that library; see:
http://article.gmane.org/gmane.comp.gnu.mingw.user/897/
and also:
http://www.libsdl.org/faq.php?action=listentries&category=7#55
Katarzyna Matylla
2010-01-06 10:21:32 UTC
Permalink
Post by C. Marcano
Could you tell me, please, what could be happening or refer to sites
containing the solution?
Two simple ideas:
1. You forgot the main() function. ;-) (or named ir Main() or something
like that).
2. You're using Allegro and forgot the END_OF_MAIN() macro.
Andrew Fleenor
2010-01-07 19:42:46 UTC
Permalink
Post by C. Marcano
I am just starting to use cygwin/gcc/mingw environment. So, I am
a novice.
I am tryng to compile a simple C++ program, with g++. It compiles
Depending on what library you are using, you might need to make sure that your main function has exactly the right signature, ie. int main(int, char**). You definitely need to be careful of this if you use SDL.
C. Marcano
2010-01-07 23:24:56 UTC
Permalink
Hi,
I thank all of you for attempting to help me.
I am reading a lot of documentation (really, more than I expect to).
By the way,I have found a code sample of a scrensaver, which contains
its own WinMain function. So, I have coded a simple code which invokes
a rather simple WinMain() function and 'g++ -c mycode.cpp', and then
'g++ -o mycode mycode.o' and, Eureka, it generates an executable,
without warnings nor errors!
So, I think that is the way. I am working now on writtimg a more
elaborated version of that WinMain() function, in order to instruct my
program in how parameteers must be read from the cmdline, and how the
rest of the program has to interpret them.
Of course, it implies more work but it will be worth!
On the other hand, we have to be carefull because there is a lot of
no-solutions in these forums, and not all what we find is really true,
and could lead us to non sense ways, as the '-lSDMain -lSDL -mwindows'
'solution', that I encountered which does not solve the problem at
all, mainly when I don't need Simple DirectMedia Layer at all!
Taking a positive actitude, those comments make me learn about SDL and
other interesting things!
Thanks,
Markanikoff
Post by Andrew Fleenor
Post by C. Marcano
I am just starting to use cygwin/gcc/mingw environment. So, I am
a novice.
I am tryng to compile a simple C++ program, with g++. It compiles
Depending on what library you are using, you might need to make sure that your main function has exactly the right signature, ie. int main(int, char**). You definitely need to be careful of this if you use SDL.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
MinGW-users mailing list
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/mingw-users
Tor Lillqvist
2010-01-07 23:40:13 UTC
Permalink
There should be no need to use a WinMain() instead of a main() unless
you specifically want to, for some reason. Don't make it harder and
more complex than necessary for yourself.

Just use a normal int main(int argc, char **argv) . Instead of
starting with random sample programs you find on the net, that might
be full of old ballast and obsolete conventions from 16-bit Windows
days, just start with a minimal C++ Hello, World program, identical to
one you could use on POSIX systems, like this:

#include <iostream>

int
main (int argc, char **argv)
{
std::cout << "Hello there" << std::endl;
return 0;
}

This builds fine with g++ --pedantic -Wall -o foo.exe foo.cpp .

Then add more code as needed.

--tml
C. Marcano
2010-01-07 23:37:23 UTC
Permalink
Hi,
I thank all of you for attempting to help me.
I am reading a lot of documentation (really, more than I expect to).
By the way,I have found a code sample of a scrensaver, which contains
its own WinMain function. So, I have coded a simple code which invokes
a rather simple WinMain() function and 'g++ -c mycode.cpp', and then
'g++ -o mycode mycode.o' and, Eureka, it generates an executable,
without warnings nor errors!
So, I think that is the way. I am working now on writtimg a more
elaborated version of that WinMain() function, in order to instruct my
program in how parameteers must be read from the cmdline, and how the
rest of the program has to interpret them.
Of course, it implies more work but it will be worth!
On the other hand, we have to be carefull because there is a lot of
no-solutions in these forums, and not all what we find is really true,
and could lead us to non sense ways, as the '-lSDMain -lSDL -mwindows'
'solution', that I encountered which does not solve the problem at
all, mainly when I don't need Simple DirectMedia Layer at all!
Taking a positive actitude, those comments make me learn about SDL and
other interesting things!
Thanks,
Markanikoff
Post by Andrew Fleenor
Post by C. Marcano
I am just starting to use cygwin/gcc/mingw environment. So, I am
a novice.
I am tryng to compile a simple C++ program, with g++. It compiles
Depending on what library you are using, you might need to make sure that your main function has exactly the right signature, ie. int main(int, char**). You definitely need to be careful of this if you use SDL.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
MinGW-users mailing list
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/mingw-users
C. Marcano
2010-01-07 23:59:28 UTC
Permalink
Hi,
I thank all of you for attempting to help me.
I am reading a lot of documentation (really, more than I expect to).
By the way,I have found a code sample of a scrensaver, which contains
its own WinMain function. So, I have coded a simple code which invokes
a rather simple WinMain() function and 'g++ -c mycode.cpp', and then
'g++ -o mycode mycode.o' and, Eureka, it generates an executable,
without warnings nor errors!
So, I think that is the way. I am working now on writtimg a more
elaborated version of that WinMain() function, in order to instruct my
program in how parameteers must be read from the cmdline, and how the
rest of the program has to interpret them.
Of course, it implies more work but it will be worth!
On the other hand, we have to be carefull because there is a lot of
no-solutions in these forums, and not all what we find is really true,
and could lead us to non sense ways, as the '-lSDMain -lSDL -mwindows'
'solution', that I encountered which does not solve the problem at
all, mainly when I don't need Simple DirectMedia Layer at all!
Taking a positive actitude, those comments make me learn about SDL and
other interesting things!
Thanks,
Markanikoff
Post by Andrew Fleenor
Post by C. Marcano
I am just starting to use cygwin/gcc/mingw environment. So, I am
a novice.
I am tryng to compile a simple C++ program, with g++. It compiles
Depending on what library you are using, you might need to make sure that your main function has exactly the right signature, ie. int main(int, char**). You definitely need to be careful of this if you use SDL.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
MinGW-users mailing list
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.
_______________________________________________
https://lists.sourceforge.net/lists/listinfo/mingw-users
Continue reading on narkive:
Loading...