Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C++ questions


  • Please log in to reply
23 replies to this topic

#1 hispaladin

hispaladin

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 20 June 2013 - 08:06 AM

Ok so here is the situation.  I am just getting started with C++ and have very little experience with programming.  I have taken a class on pseudo-code and have done a little scripting in computer games as well as writing some batch files and a little bit of powershell.  I know that none of that has any real direct connection with C++ but it gives me a basic understanding of syntax.  I am using Visual Studio Express 2012 for Win 8.  I am going through a book on C++ but am having some issues that I just don't understand.  I am trying to write a simple "Hello world" type program and I am getting some errors that I don't understand at all.  I am going to include some screenshots of what I have and what I am seeing.

This is the extent of the code that the program contains.  not much to have issues with.

2ei.png

This is the errors I am getting when I try to compile (or debug, whatever F5 does)

f896.png

Edit: Ok so that pic is way to small to read so here is the errors I am getting

 

Error 1 error LNK2019: unresolved external symbol "public: virtual void __cdecl Testapp::App::[Windows::UI::Xaml::IApplicationOverrides]::OnLaunched(class Windows::ApplicationModel::Activation::LaunchActivatedEventArgs ^)" (?OnLaunched@?QIApplicationOverrides@Xaml@UI@Windows@@App@Testapp@@U$AAAXP$AAVLaunchActivatedEventArgs@Activation@ApplicationModel@4@@Z) referenced in function "public: virtual long __stdcall Testapp::App::[Windows::UI::Xaml::IApplicationOverrides]::__abi_Windows_UI_Xaml_IApplicationOverrides____abi_OnLaunched(class Windows::ApplicationModel::Activation::LaunchActivatedEventArgs ^)" (?__abi_Windows_UI_Xaml_IApplicationOverrides____abi_OnLaunched@?QIApplicationOverrides@Xaml@UI@Windows@@App@Testapp@@U$AAGJP$AAVLaunchActivatedEventArgs@Activation@ApplicationModel@4@@Z) C:\Users\davidc\documents\visual studio 2012\Projects\Testapp\Testapp\pch.obj Testapp
 
Error 2 error MSB6006: "link.exe" exited with code 1120. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets 611 5 Testapp
 
Error 3 error LNK2019: unresolved external symbol "public: __cdecl Testapp::App::App(void)" (??0App@Testapp@@Q$AAA@XZ) referenced in function "public: void __thiscall <lambda_00f31d95cc6fc41c2b611012bf8edc35>::operator()(class Windows::UI::Xaml::ApplicationInitializationCallbackParams ^)const " (??R<lambda_00f31d95cc6fc41c2b611012bf8edc35>@@QBEXP$AAVApplicationInitializationCallbackParams@Xaml@UI@Windows@@@Z) C:\Users\davidc\documents\visual studio 2012\Projects\Testapp\Testapp\XamlTypeInfo.g.obj Testapp
 
Error 4 error LNK1120: 2 unresolved externals C:\Users\davidc\documents\visual studio 2012\Projects\Testapp\Debug\Testapp\Testapp.exe Testapp
 

I have this sneaking suspicion that this is not all that hard to resolve but I don't know how to do it.

(P.S. the book I am going through is not based in VS2012, its in 2008 I think, would that cause me a lot of headaches?)


Edited by hispaladin, 20 June 2013 - 08:11 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:38 PM

Posted 20 June 2013 - 10:35 AM

Posting your code would be more helpful. Although we can make educated guesses based on the error messages, it is more helpful to actually see your code.



#3 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 20 June 2013 - 11:59 AM

Sorry I had a screenshot of the code but it didn't work, here is the code

#include "pch.h"
#include <iostream>
using namespace std;
int main (void)
{
int x = 0;
while (x<5)
{
cout << "Welcome to C++" << endl;
x++;
}
return 0;
}

 

Like I said its just a simple hello world type program but I cant get it to work.  It should output "Welcome to C++" five times, each on a separate line.  On another note the second error I listed above went away by itself  :scratchhead:


Edited by hispaladin, 20 June 2013 - 12:01 PM.


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:38 PM

Posted 20 June 2013 - 02:32 PM

Let's dissect one of the error messages:

Error 3 error LNK2019: unresolved external symbol "public: __cdecl Testapp::App::App(void)" (??0App@Testapp@@Q$AAA@XZ) referenced in function "public: void __thiscall <lambda_00f31d95cc6fc41c2b611012bf8edc35>::operator()(class Windows::UI::Xaml::ApplicationInitializationCallbackParams ^)const " (??R<lambda_00f31d95cc6fc41c2b611012bf8edc35>@@QBEXP$AAVApplicationInitializationCallbackParams@Xaml@UI@Windows@@@Z) C:\Users\davidc\documents\visual studio 2012\Projects\Testapp\Testapp\XamlTypeInfo.g.obj Testapp

"unresolved external symbol" means that your program said "there will be something called <<the missing symbol>>", but never actually defined that symbol. In this case, the linker is looking for "public: __cdecl Testapp::App::App(void)".

"lambda_" is somewhat strange because your code does not contain any lambda expressions.

"Windows::UI::Xaml" shouldn't appear unless you are writing a Windows Store XAML app, which would be C++/CX, not C++.

Are you sure you picked the right project type when you created it in Visual Studio? You want to pick "Windows Console Application".

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 20 June 2013 - 04:20 PM

At this point billy I am sure that I wrote the code that I listed above and that is all I am sure of.  If I used the wrong tool to write this program or something of the nature I am all ears to get pointed to the right program.  All I ask is that based on what you have seen I am trying to learn and am starting at the absolute bottom with the "Hello world" program, so please be nice to me  :blink: its all still very new to me.



#6 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 20 June 2013 - 04:24 PM

OK if I go to new Project and choose Visual C++ my options are a blank app (XAML), a Grid App (XAML), Split App (XAML), and some others that I know I don't want.  When I choose the blank app it is not really blank, it starts with a bunch of code already in it.  I am using Microsoft Visual Studio Express 2012 for Windows 8.  Is there anyone in here who is familiar enough with it to point me in the right direction as to where to start making a basic beginner app?



#7 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:38 PM

Posted 20 June 2013 - 04:28 PM

It looks like you installed the "Visual Studio Express 2012 for Windows 8" instead of "Visual Studio Express 2012 for Windows Desktop". "Express for Windows 8" can't build traditional console applications like you're trying to do here.
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#8 DarkSnake-Kobra

DarkSnake-Kobra

  • Members
  • 633 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Iowa, USA
  • Local time:07:38 PM

Posted 20 June 2013 - 06:07 PM

I suggest you install CodeBlocks with the MinGW compiler. It's great for a beginner. Plus it's lighter and less complex to install.

 

 

http://www.codeblocks.org/downloads/26

 

Note that they have a user setup now which install it in your directory while the normal setup will install it in Program Files.


Edited by DarkSnake-Kobra, 20 June 2013 - 06:10 PM.


#9 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 21 June 2013 - 08:09 AM

Thanks for the explanation Billy, I found the visual C++ 2008 version (which is what my book uses) and it is working a lot better though I may give the newer express for windows desktop a try as it would be good to get used to the newer software.  Thanks for the help all around guys.



#10 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:38 PM

Posted 21 June 2013 - 12:15 PM

MinGW is a decent Windows compiler -- just keep in mind it does not support quite a lot of what's available on the Windows platform, e.g. COM or Unicode support.
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#11 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 21 June 2013 - 03:27 PM

OK so I switched compilers and now got that program to work with flying colors, now on to a bigger program that I have been wanting to make for a very long time.  I will post the code I have so far and comment on it as to where I am having issues.  First of all know that this is the first part of what will (eventually) be a much larger program.  

 

Ok I am not getting any error messages but if I input certain numbers the program will only produce a 0 instead of the correct data.  

The concept is that two ships are going to fight and combat is based on their stats (power, tracking, armor, and maneuverability)  power and armor work against each other and tracking and maneuverability work against each other.  

I am testing with these numbers but have had the same outcome with several other sets

atp = 7

att = 3

ata = 9

atm = 2

athp and dfhp really don,t matter other than how long the loop lasts

dfp = 3

dft = 6

dfa = 2

dfm = 9

 

#include <iostream>
using namespace std;
short atp, att, ata, atm, dfp, dft, dfa, dfm;
float hit;
double dam;
double athp, dfhp;
short shot;
int main ()
{
cout << "input attackers power, tracking, armor, maneuverability, and HP";
cin >> atp;
cin >> att;
cin >> ata;
cin >> atm;
cin >> athp;
cout << "input defenders power, tracking, armor, maneuverability, and HP";
cin >> dfp;
cin >> dft;
cin >> dfa;
cin >> dfm;     //line 20
cin >> dfhp;
while (athp>0 && dfhp>0)
{
hit = (att / dfm) / 2 * 100;  //this line fails when the equation would produce a fraction at any point, instead it produces only 0, even when the end number should be greater than 0
shot = rand() % 100 + 1;
cout << "shot is " << shot << "hit is " << hit << endl;   //reference data
if (hit>shot)
{    //line 28
dam = atp / dfa;  //this line will not produce an output less than 0 such as .33 and will round any decimal values
cout << "damage is " << dam << endl;
dfhp = dfhp - dam;
}
cout << "Defenders HP is:" << dfhp << endl;
hit = (dft / atm) / 2 * 100;  //this line fails when the equation would produce a fraction at any point, instead it produces only 0, even when the end number should be greater than 0
shot = rand() % 100 + 1;
cout << "shot is " << shot << "hit is " << hit << endl;  //reference data
if (hit>shot)
{
dam = dfp / ata;
cout << "damage is " << dam << endl;
athp = athp - dam;  //this line will not produce an output less than 0 such as .33 and will round any decimal values
}
cout << "Attackers HP is:" << athp << endl;
}
if (athp>0 && dfhp<=0)
{
cout << "attacker wins";
}
else if (dfhp>0 && athp<=0)
{
cout << "defender wins";
}
else 
{
cout << "tie, all is lost";
}
return 0;
}

 

 

 

So any ideas on why I am having these issues??


Edited by hispaladin, 21 June 2013 - 03:29 PM.


#12 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:38 PM

Posted 21 June 2013 - 03:32 PM

Hi there.

hit = (att / dfm) / 2 * 100; //this line fails when the equation would produce a fraction at any point, instead it produces only 0, even when the end number should be greater than 0

att, df, 2, and 100 have types short, short, int, and int, respectively. They are all integral types. A fractional result is impossible.

dam = atp / dfa; //this line will not produce an output less than 0 such as .33 and will round any decimal values

Same problem, atp and dfa are integral types; the result of division against integral types is another integral type.

You might also want to read this: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#13 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 21 June 2013 - 03:45 PM

OK so would changing the types all to float and entering the numbers as 2.0 and 100.0 give the proper result?  

(cant wait for a response so I am going to try it :woot:



#14 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 21 June 2013 - 03:48 PM

:bananas: IT WORKS!!! :bananas:   

 

Thanks a bunch and I will look over that link you sent



#15 hispaladin

hispaladin
  • Topic Starter

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:07:38 PM

Posted 25 June 2013 - 11:54 AM

OK so a few more C++ problems.  I am getting a "Cannot find or open the PDB file." error when I try to run the program.  I was getting several and went to the debug > options and settings > and set to pull the symbols from microsoft and that fixed all but one of the errors.  The error I am still getting is when it tries to pull a file from my Symantec endpoint protection folder.  I am stumped by this and have no idea why it would want a .dll from symantec but that is the problem I am having now.

Here is the error 

'boardgame.exe' (Win32): Loaded 'C:\ProgramData\Symantec\Symantec Endpoint Protection\12.1.3001.165.105\Data\Definitions\BASHDefs\20130620.011\UMEngx86.dll'. Cannot find or open the PDB file.

 

I was getting about 6 more like it but getting the debug symbols from Microsoft fixed those.

Any ideas?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users