error LNK2019, how do i fix it?

this is the code im using, when i goto build it i works fine then as its about to finish i ge tthe LNK2019 error, why?

#include <iostream>

int main()

{

usingnamespace std;

int carrot;

cout << "how many carrots do you have? ";

cin >> carrot;

cout << endl;

carrot = carrot - 2;

cout << "cruch crunch, i ate somse of your carrots. you now have " << carrot << " carotts" << endl;

return 0;

}

[892 byte] By [daman543] at [2007-12-16]
# 1
I just tried compiling the sample you supplied nad it worked fine for me (using VS2005 beta2).

Could you share the compilation command, you can do that by looking at the build log? Or share the steps on how you created the project?
Thanks,
Ayman Shoukry
VC++

AymanShoukry at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2
Build Log

- Build started: Project: asdf, Configuration: Debug|Win32 -

Command Lines
This edition of Visual C++ does not support the optimizing compiler. This edition of Visual C++ does not support the optimizing compiler. Creating temporary file "c:\Documents and Settings\Jason Kennedy\My Documents\Visual Studio Projects\asdf\Debug\RSP000001.rsp" with contents [ /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1 /MLd /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /TP ".\asdf.cpp" ] Creating command line "cl.exe @"c:\Documents and Settings\Jason Kennedy\My Documents\Visual Studio Projects\asdf\Debug\RSP000001.rsp" /nologo" Creating temporary file "c:\Documents and Settings\Jason Kennedy\My Documents\Visual Studio Projects\asdf\Debug\RSP000002.rsp" with contents [ /OUT:"Debug/asdf.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"Debug/asdf.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ".\Debug\asdf.obj" ] Creating command line "link.exe @"c:\Documents and Settings\Jason Kennedy\My Documents\Visual Studio Projects\asdf\Debug\RSP000002.rsp""
Output Window
Compiling... asdf.cpp Linking... LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup Debug/asdf.exe : fatal error LNK1120: 1 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\Jason Kennedy\My Documents\Visual Studio Projects\asdf\Debug\BuildLog.htm" asdf - 2 error(s), 0 warning(s)

thats the build log, i have VC++ .NET 2k3 and WIN XP PRO, 2.6GHz P4, 512MB RAM
daman543 at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 3

From the link command, you are using /subsystem:windows, if you are going to use subsystem:windows then you need to implement your own WinMain (not main). If you are using just "main" then you need to use a win32 console application (/subsytem:console).

To know more about the /subsystem option, please see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_.2f.subsystem.asp

As for using WinMain:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/winmain.asp

Hope this helps!

Thanks,
Ayman Shoukry
VC++

AymanShoukry at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 4
awsome, that was it, thanks much
daman543 at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 5

Hi all,

I'm a newbie to Visual C++ (and C++ in general), and first I'd like to say thanks -- I had multiple problems with my first program running correctly, and found most of the answers here, in previous threads.

I did get it running, but now I have a question about the debugger.

Like daman above, I am teaching myself using Prata's C++ Primer Plus and tried one of those "carrots" programs like the one above.

When I ran the debugger on the program after I got all the aforementioned problems fixed, the program would start fine but dump me back out when I input a number. Output from the debugger is below, but what really confuses me is that when I clean the program and start it without debugging, it runs just fine. In addition, I can only get it to run from inside VC without debugging -- the executable that's created does the same thing as the debugged version (ie crashes).

I'm using a Win32 console rather than the Windows subsystem, so that doesn't seem to be the problem. My build log is massive compared to daman's, but I included the info below.

Thanks in advance for your help and patience.

The Output from the debugger:

'carrots_try3.exe': Loaded 'D:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\debug\carrots_try3.exe', Symbols loaded.

'carrots_try3.exe': Loaded 'C:\WINNT\system32\NTDLL.DLL', Cannot find or open a required DBG file.

'carrots_try3.exe': Loaded 'C:\WINNT\system32\msvcr80d.dll', No symbols loaded.

'carrots_try3.exe': Loaded 'C:\WINNT\system32\msvcrt.dll', No symbols loaded.

'carrots_try3.exe': Loaded 'C:\WINNT\system32\KERNEL32.DLL', Cannot find or open a required DBG file.

'carrots_try3.exe': Loaded 'C:\WINNT\system32\msvcp80d.dll', No symbols loaded.

The program '[1952] carrots_try3.exe: Native' has exited with code 0 (0x0).

LOG:

Command Lines
Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004516842352.rsp" with contents [ /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp"Debug\carrots_try3.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\carrots_try3.cpp" ] Creating command line "cl.exe @"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004516842352.rsp" /nologo /errorReport:prompt" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004616842352.rsp" with contents [ /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yc"stdafx.h" /Fp"Debug\carrots_try3.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\stdafx.cpp" ] Creating command line "cl.exe @"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004616842352.rsp" /nologo /errorReport:prompt" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\TMP00004716842352.tmp" with contents [ 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ ".\\Debug\\carrots_try3.exe.embed.manifest" ] Creating command line "rc.exe /fo".\Debug\carrots_try3.exe.embed.manifest.res" "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\TMP00004716842352.tmp"" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004816842352.rsp" with contents [ /OUT:"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\Debug\carrots_try3.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:"Debug\carrots_try3.exe.intermediate.manifest" /DEBUG /PDB:"d:\program files\microsoft platform sdk\bin\carrots_try3\debug\carrots_try3.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib ".\debug\stdafx.obj" ".\debug\carrots_try3.obj" ".\Debug\carrots_try3.exe.embed.manifest.res" ] Creating command line "link.exe @"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004816842352.rsp" /NOLOGO /ERRORREPORT:PROMPT" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004916842352.rsp" with contents [ /out:".\debug\carrots_try3.exe.embed.manifest" /notify_update /manifest ".\debug\carrots_try3.exe.intermediate.manifest" ] Creating command line "mt.exe @"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004916842352.rsp" /nologo" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\BAT00004A16842352.bat" with contents [ @echo Manifest resource last updated at %TIME% on %DATE% > ".\debug\mt.dep" ] Creating command line """d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\BAT00004A16842352.bat""" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\TMP00004B16842352.tmp" with contents [ 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ ".\\Debug\\carrots_try3.exe.embed.manifest" ] Creating command line "rc.exe /fo".\Debug\carrots_try3.exe.embed.manifest.res" "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\TMP00004B16842352.tmp"" Creating temporary file "d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004C16842352.rsp" with contents [ /OUT:"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\Debug\carrots_try3.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:"Debug\carrots_try3.exe.intermediate.manifest" /DEBUG /PDB:"d:\program files\microsoft platform sdk\bin\carrots_try3\debug\carrots_try3.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib ".\debug\stdafx.obj" ".\debug\carrots_try3.obj" ".\Debug\carrots_try3.exe.embed.manifest.res" ] Creating command line "link.exe @"d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\RSP00004C16842352.rsp" /NOLOGO /ERRORREPORT:PROMPT" 
Output Window
Compiling... stdafx.cpp Compiling... carrots_try3.cpp Compiling manifest to resources... Linking... LINK : d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\Debug\carrots_try3.exe not found or not built by the last incremental link; performing full link LINK : warning LNK4067: ambiguous entry point; selected 'mainCRTStartup' Embedding manifest... 
Results
Build log was saved at "file://d:\Program Files\Microsoft Platform SDK\Bin\carrots_try3\carrots_try3\Debug\BuildLog.htm" carrots_try3 - 0 error(s), 1 warning(s) 

Evangelina at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 6

I don't think it did dump you straight back out. I think the program worked properly, finished, and then closed down.

If you look very very very closely at the output, you'll probably see that it prints out the final message correctly before it quickly exits. You'll have to be eagle-eyed to catch it (blink and you'll miss it) because once it prints out the final number of carrots, the program will end and close down.

We get this problem quite often... the programmers may look very very closely at the output, but they don't look very very VERY closely at it. Hence they miss the output before the program closes, and think that their program crashed.

If you're not eagle-eyed enough to catch it, I suggest adding a breakpoint at the "return 0;" line before debugging. This will stop the program long enough for you to see the results.

OShah at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 7
Well, that's actually funny, in a disturbing kind of way. Thanks so much for your help--the breakpoint slowed it down just enough for me to catch the output.
Evangelina at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...
# 8

Help.. I'm new to C++ and I have problems building this project. The source code is as follows:

#include "stdafx.h"

#include <string.h>

#include <windows.h>

#include <iostream.h>

void main(){

try{

HCRYPTPROV hProv;

BOOL didItWork = CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, NULL);

if(!didItWork){

if(GetLastError()==NTE_BAD_KEYSET){

didItWork = CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_NEWKEYSET);

if(!didItWork){

throw GetLastError();

}

}else{

throw GetLastError();

}

}

HCRYPTKEY myKey = 0;

didItWork = CryptGenKey(hProv, CALG_AES_128, CRYPT_EXPORTABLE, &myKey);

if(!didItWork){

throw GetLastError();

}

const char *plaintext = "PlainText";

unsigned char buffer[256];

unsigned long strSize = strlen(plaintext)+1;

memcpy(buffer, plaintext, strlen(plaintext)+1);

didItWork = CryptEncrypt(myKey, NULL, TRUE, NULL, buffer, &strSize, sizeof(buffer));

if(!didItWork){

throw GetLastError();

}

CryptDestroyKey(myKey);

CryptReleaseContext(hProv, NULL);

}catch(DWORD error){

LPWSTR msgbuffer;

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), msgbuffer, sizeof(msgbuffer), NULL);

cerr<<msgbuffer<<endl<<flush;

}

}

Here is the build log file that was generated after I tried to build the project:

Build Log

Build started: Project: encryption, Configuration: Debug|Win32

Command Lines
Creating temporary file "c:\Documents and Settings\Michelle Teo\My Documents\Visual Studio 2005\Projects\encryption\Debug\RSP00001626162308.rsp" with contents [ /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp"Debug\encryption.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\encryption.cpp" ] Creating command line "cl.exe @"c:\Documents and Settings\Michelle Teo\My Documents\Visual Studio 2005\Projects\encryption\Debug\RSP00001626162308.rsp" /nologo /errorReport:prompt" Creating temporary file "c:\Documents and Settings\Michelle Teo\My Documents\Visual Studio 2005\Projects\encryption\Debug\RSP00001726162308.rsp" with contents [ /OUT:"Debug\encryption.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:"Debug\encryption.exe.intermediate.manifest" /DEBUG /PDB:"c:\documents and settings\michelle teo\my documents\visual studio 2005\projects\encryption\debug\encryption.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib ".\debug\stdafx.obj" ".\debug\encryption.obj" ".\Debug\encryption.exe.embed.manifest.res" ] Creating command line "link.exe @"c:\Documents and Settings\Michelle Teo\My Documents\Visual Studio 2005\Projects\encryption\Debug\RSP00001726162308.rsp" /NOLOGO /ERRORREPORT:PROMPT"
Output Window
Compiling... encryption.cpp c:\program files\microsoft visual studio 8\vc\include\streamb.h(158) : warning C4244: 'return' : conversion from '__w64 int' to 'int', possible loss of data c:\program files\microsoft visual studio 8\vc\include\streamb.h(159) : warning C4244: 'return' : conversion from '__w64 int' to 'int', possible loss of data c:\program files\microsoft visual studio 8\vc\include\streamb.h(170) : warning C4244: 'return' : conversion from '__w64 int' to 'int', possible loss of data c:\documents and settings\michelle teo\my documents\visual studio 2005\projects\encryption\encryption.cpp(38) : warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned long', possible loss of data c:\documents and settings\michelle teo\my documents\visual studio 2005\projects\encryption\encryption.cpp(51) : warning C4700: uninitialized local variable 'msgbuffer' used Linking... encryption.obj : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function _main encryption.obj : error LNK2019: unresolved external symbol __imp__CryptDestroyKey@4 referenced in function _main encryption.obj : error LNK2019: unresolved external symbol __imp__CryptEncrypt@28 referenced in function _main encryption.obj : error LNK2019: unresolved external symbol __imp__CryptGenKey@16 referenced in function _main encryption.obj : error LNK2019: unresolved external symbol __imp__CryptAcquireContextW@20 referenced in function _main Debug\encryption.exe : fatal error LNK1120: 5 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\Michelle Teo\My Documents\Visual Studio 2005\Projects\encryption\Debug\BuildLog.htm" encryption - 6 error(s), 5 warning(s)

Can anyone tell me what's going on and how to solve the problem? Thanks.. :)

truelove84 at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...