max-holz

When I try to compile with VS2005 enabling unicode support I get that error.

// standard windows headers
#define _WIN32_WINNT 0x0400
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>


#include "strconv.h"

extern int utf8_main(int argc, char **argv);

//============================================================
// main
//============================================================

#ifdef __GNUC__
int main(int argc, char **a_argv)
#else // !__GNUC__
int _tmain(int argc, TCHAR **argv)
#endif // __GNUC__
{
int i, rc;
char **utf8_argv;

#ifdef __GNUC__
TCHAR **argv;
#ifdef UNICODE
// MinGW doesn't support wmain() directly, so we have to jump through some hoops
extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, int expand_wildcards, int *startupinfo);
WCHAR **wenviron;
int startupinfo;
__wgetmainargs(&argc, &argv, &wenviron, 0, &startupinfo);
#else // !UNICODE
argv = a_argv;
#endif // UNICDE
#endif // __GNUC__

/* convert arguments to UTF-8 */
utf8_argv = (char **) malloc(argc * sizeof(*argv));
if (utf8_argv == NULL)
return 999;
for (i = 0; i < argc; i++)
{
utf8_argvIdea = utf8_from_tstring(argvIdea);
if (utf8_argvIdea == NULL)
return 999;
}

/* run utf8_main */
rc = utf8_main(argc, utf8_argv);

/* free arguments */
for (i = 0; i < argc; i++)
free(utf8_argvIdea);
free(utf8_argv);

#ifdef MALLOC_DEBUG
{
void check_unfreed_mem(void);
check_unfreed_mem();
}
#endif

return rc;
}

This code is written mainly for MinGW gcc compiler but without unicode support enabled compiles well under MSVC too. I don't understand where the error could be.



Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

Are you sure you have Unicode support enabled The main for a Unicode program is wmain, but the error message indicates it is looking for main.






Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

max-holz

Yes I'am sure. I use the command line compiler and this a piece of the .mak file:

UNICODE = 1

.......

CC += /Ox
CC += /O2
CC += /Ot
CC += /MT
CC += /arch:SSE2
LD += /OPT:NOWIN98

MAXOPT = 1
ifdef MAXOPT
CC += /GL
LD += /LTCG
endif

............

ifdef UNICODE
DEFS += -DUNICODE -D_UNICODE
endif

I'am trying to compile a command line app.





Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

In tchar.h is:

#ifdef _UNICODE
#define _tmain   wmain
#else  /* ndef _UNICODE */
#define _tmain   main
#endif /* _UNICODE */

That is a simplified version of what is really there; you can look at it yourself for the details.

The source code you have uses _tmain as in:

int _tmain(int argc, TCHAR **argv)

Yet the error message says that _main is unresolved. I think that the underscore ("_") can be ignored but since it is main and not wmain I think it is certain that it is looking for a non-Unicode program.

Note that it is a linker message. Therefore it is the linker that does not know it is a Unicode program. I don't know what the option is for the linker, but I assume it is easy enough to find. If there is a separate option to specify Unicode for the linker, then that is what you need.

Note that you did not specify in your original question that you are using a makefile. It would have helped to have mentioned that originally.






Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Holger Grund

Simple Samples wrote:

Yet the error message says that _main is unresolved. I think that the underscore ("_") can be ignored but since it is main and not wmain I think it is certain that it is looking for a non-Unicode program.

That's probably not entirely accuate. There is some linker magic involved in the entry point selection. I believe, the linker will automatically look for the correct CRT entry point (Wilted Flower[Win]mainCRTStartup) if it sees a single user code entrypoint Wilted FlowerWinMain or Wilted FlowerMain. If you, set /SUBSYSTEM:CONSOLE it will by default look for the non-Unicode variant.

AFAICT, the error message simply suggest that no entry point was found, but the /SUBSYSTEM:CONSOLE switch was given.

BTW: the leading underscore is the __cdecl name mangling scheme for the x86 ABI. The compiler will automatically select __cdecl for main/wmain at file scope with correct signature (i.e. it will get C linkage).

I would suggest to run dumpbin /SYMBOLS on the object file that supposedly has a definition for wmain. Does it list main What does its symbol table entry look like If it is not what you expect, can you try to preprocess the source file

-hg





Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

See MAME Compiling Board - Re: Error compiling 111u3. I don't know what MAME is but they seem to be having the same problem.




Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

Based on tests, either main or wmain can be used when _UNICODE is defined.




Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

Also, I cannot find any linker option to specify Unicode, except the entry point. Perhaps the makefile is specifying an entry point. If so, then the way an entry point is specified (perhaps the default value) has changed for VC 2005.




Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

Until you get an easier solution, one way to solve the problem is to create a separate test version of the project and chop out peices until the problem goes away. If you can remove the parts that are obviously not relevant in the beginning and the problem persists then remove smaller portions thereafter then it is likely to be relatively quick.

If it were me, I would likely try creating a project that does not use a makefile. That will take time but once you have it done it will be easier in the future. I do understand that you need to remain compatible with future versions of the software but perhaps you don't need to retain the makefile. Again, I understand that compatibility might make that solution impractical.






Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

max-holz

Added some lines in the makefile:

LD += /SUBSYSTEM:CONSOLE

DEFS += -D_CRT_SECURE_NO_DEPRECATE -DXML_STATIC -D__inline__=__inline -Dsnprintf=_snprintf -Dvsnprintf=_vsnprintf

now the error is changed:

LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main





Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Ben Anderson MSFT

Have you tried compiling with the /P option to cl.exe to preprocess the file and see what your macros actually expand to It looks like you've got enough #ifdef's and macros in there that there might be something simple we're not seeing.




Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

LawrenceJob.co.uk

It has taken me three days to resolve but you have to modify Zi command line things etc. This is what my command line looked like in various places. The trouble is, I cannot remember what I did so I'll put it all up:

C/C++
/D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_VC80_UPGRADE=0x0600" /Gm /EHsc /MTd /Fp".\Debug/ClientWindow.pch" /Fo".\Debug/" /Fd".\Debug/" /W3 /nologo /c /Zi /TP /errorReport:prompt

LINKER
/OUT:".\Debug/ClientWindow.exe" /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:".\Debug\ClientWindow.exe.intermediate.manifest" /DEBUG /PDB:".\Debug/ClientWindow.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT ws2_32.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib

MANIFEST TOOL
/nologo /out:".\Debug\ClientWindow.exe.embed.manifest" /notify_update

RESOURCES
/d "_DEBUG" /d "_VC80_UPGRADE=0x0600" /l 0x409 /fo".\Debug/ClientWindow.res"

XML DOCUMENT GENERATOR
"ClientWindow" /nologo /Fo"c:\Documents and Settings\Administrator\Desktop\Experiments\CPP\Remote Desktop T2\Client\Debug\ClientWindow.xml"

BROWSE INFORMATION
/nologo /o ".\Debug/ClientWindow.bsc"

And that's about it (in my project). The reason I do not know what I did is last night, I modified some last few things and only this morning debugged it







Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

I notice that there are not definitions of UNICODE and _UNICODE in the compile command. I think that means you are compiling without Unicode. Are You If you are not, then that explains why it did not work previoulsly (when you were compiling with Unicode) and it works now.




Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

LJuk

Who are you talking to Me I am not the person who started the post... I'm just developing some remote desktop software and got 53 of those errors but after a day, resolved them by tweaking the properties..

Weirdly, I think rebooting helped this one...

Note to all... Definitely check the /Zi command line thing.. worth tweaking if those errors are consistent.






Re: Visual C++ Language error LNK2019: unresolved external symbol _main referenced in function __tmainCRTStartup

Simple Samples

Sorry about confusing who replied.

I doubt that /Zi has anything to do with the problem in the original question.

The problem is nearly certainly related to the project; note that the source code has #defines and such that attempt to make the code less dependent on the compiler. My guess is that the only thing in common is the error message.