Incorrect main method running in visual studio - c++

I'm trying to do some tutorial C++ programs to familiarize myself with the language. I'm using Visual Studio 2010. I have a Visual Studio solution with two projects - I'll just call them projectA and projectB. Each project has a source file with its own main method. However, when I try to run the program in projectB, the program in projectA runs instead. I'm coming from an Eclipse IDE where projects separate the programs. I've some msdn articles on solutions and projects, but I haven't seen anything about being unable to have multiple source files with main methods in them. Can someone help to clarify the Visual Studio Solution/Project structure for me, please.

Right click on the project you want to run, and select Set as StartUp Project

You have to right click on the project and "Set as Startup Project" to tell Visual Studio which project you want to actually run.

I hope this is a nice simple fix: if you look at your solution and have both projects open, you should be able to right click one of them and set it as default (Set as Startup Project), (which sounds like at the moment is set to projectA).
I have highlighted the relevant option in the menu picture:

Either you can right click on the project in the Project Explorer and select Set As StartUp Project or you can use meny item Project and also select Set StartUp Project.

Related

In Visual Studio, can you add a folder-based project in a solution?

Visual Studio finally has the ability to open folder-only projects, which makes it great for simple web sites that serve from the file system, etc. However, I can't find a way to add one of these projects to my existing solution. Whenever I try opening it, it tells me to close it.
So, how can you add a folder-based project to Visual Studio solution? Or can you?

Visual Studio 2012 everything out of date

In Visual Studio 2012, I usually use C# applications, which work fine. Now that I feel like I have a strong grasp of C#, I've decided to move on to C++. I have changed no preferences. All of my C++ projects say that the project is out of date. Here are my steps:
File -> New Project
Click "Visual C++" tab -> Win32 Console Application
Change nothing and click OK
Click Finish for the Win32 Application Wizard
Press F5 to run, or click the button (which says "Local Windows Debugger").
I'm not sure if I'm making a mistake or if there are missing dependencies. My question is, what is causing this and how can I prevent this message? If you don't know, then what are some things that I can do to find out?
what is causing this
=> Two possible reasons :
you just created the project and have not built it before trying to launch it
OR you made some changes to the project files and tried to launch the application before building the project
how can I prevent this message?
Tick "Do not show this dialog again" and click yes : your application will automatically be built every time you want to launch it.
OR always build the project before launching it

Visual Studio 2010 File->New->Project Grayed Out

I created a solution of Win32 Project.
Then I clicked on File->New->Project and created a new Win32 Project, but added the project to the current solution, just so I could see both projects in the Solution Explorer. (Because Visual Studio can only display one solution at once, as I am told).
Now I am trying to create a third project to the solution, but when I go to File->New->Project, this option is totally grayed out.
What happened here? And how do I solve it? What I want is to be able to have many projects in the Solution Explorer, and I tried to do so by adding the projects to current solution.
I was in Debugging Mode (ie running my program). Therefore, New Project was grayed out. To fix the issue, simply exit debugging mode (Shift + F5)

Profile a c++ win32 console application with Visual Studio 2012

I have a simple (not so simple) win32 console application in c++. I would like to profile this application, but when I try to:
DEBUG > Start Performance Analysis
An error occurs: "No launchable projects are available for profiling".
Please note that the project compiles and runs normally. It's jus the profling that is not working.
How can I solve? I am on Windows 8 with Visual Studio Ultimate 2012
Note that I choose for this project a simple:
File > New Project > Win32 > Win32 Console Application (C++)
I would like to obtain something like xcode does.
A simple list for each functions or methods the cumulative time of usage.
This is the error when I try "Start performance analysis"
Note
I have tried both release mode and debug mode with both x64 and or Win32
Note2
In this project I have created two custom property sheet (to include the right opencv libraries)
- OpenCV-Release
- OpenCV-Debug
Note3
Open the projects properties.> Configration Manager > Active Solution Platform > select New > and follow my screen shot. Your perfomance analysis will run after this.
The project is not being recognised, as you have it configured with x64. (As evidenced by your first screenshot under Note)
Win32
As your project is created in the 64bit os, you need to manually link the project with the win32 sys, so the profiler will recognize the project as a win32 project.
http://en.wikipedia.org/wiki/Windows_API
I will leave this here, as it may be useful for some users.
Saving projects in Visual Studio, must be done methodically and consistently.
If a project is created and saved in a folder (for example) Folder A within the C drive and then later the folders are rearranged and the project is then in Folder A, but folder A has been moved to the D drive (or any variation of changes). Visual Studio, will not be able to find the project.
Be sure to check that all your files for this project are in the correct folders. You need to open the sub folder and make sure that all the files for your project are present.
Please see my screen shots. It doesn't matter why my folders are arranged, as they are, suffice to say, I have found it easier to keep them with the program files in the C drive.
Please note the file in the first screen shot extension vspx, is a visual studio performance report.
Visual Studio Project Folder
Visual Studio Sub Folder
This may or may not answer your question. Please advise if you need more assistance.
The short cut-
VS Release
The long steps - which give you more options
VS Debug menu
VS Configuraion Manager
Please try this (it is the same answer on both links):
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/56dcdb2a-5e30-4015-bc14-244f99f07b8b
Profiling with CMake, C++, and Visual Studio 2012
And this link as well.
Add the files to a directory outside of the project and then reference those directories in the "Additional Include Directories" in Properties -> Configuration Properties -> C/C++ -> General.
VC++ Visual Studio added .hpp files in subdirectory but get "Error: cannot open source file ..."
You can launch the performance wizard, under the Analyze tab.
This is a known bug in VS.
Without seeing your computer, it is hard to know what else, I can suggest. I do know that it's important to go through all the suggested steps to trouble shoot. If I can find anything else, I'll let you know.
Please note my project is a downloaded sample.

visual studio 2010 unable to start program .dll

I have a problem for my visual studio 2010. When I click start debugging button and it's start debugging.
It seems that there is no error "i just create one "button" on it "
But it will show Unable to start program 'c:\users\.....\xx.dll'
Does someone now how to solve it?
The second question is: when I click left button to see the "Button" source code,
why it will show all this project code? Should I revise some setting?
Visual studio will not run a .dll by itself. does your solution have an .exe project? if so, right click it and select "Set as Startup Project". if not you will need to create one, and instruct it to load the forms within your dll.
as for left clicking the button, I'm not quite sure what you are describing. can you post a picture?
In earlier versions of MSVC while running .dll, will get a dialog asking path for .exe file
But in MSVC 2010 and above there is no such option. To fix this
Right click on your dll project
Properties
Configuration Properties > Debugging. Here, in Command -> add path to your exe.
Add command arguments, if any.
You are good to go!