Microsoft Visual C++ 2010 can't debug? - c++

I installed the program, and wrote a simple C program to try it, but I couldn't build it or anything !
The debug, build and run options are all greyed out ! I can't click them
Please help :(

In Visual Studio your code needs to be in a Project before you can Build/Debug it. You can't just open your .cpp file and run it. (When you create a project, Visual Studio creates a solution to contain it (a solution can contain many projects))
You can Create a new project using File -> New -> Project :
then add your code to that project or if the you already have your source code files you can use the "Create a Project from Existing Code Files" wizard which is available under File -> New -> Project from existing code

Related

Multiple file compilation in visual C++ 2010

I have a very specific question in regards to visual C++ 2010 express. I have looked everywhere but can't find instructions on how to compile several source files. I have programmed on Unix at the command line and am trying to learn visual C++ 2010. I am using a header file that contains the function declarations and global variables. I don't know if this is the correct venue to ask this question but if anyone knows of some place where I can get the answer I would be grateful
Thanks,
Ral
If you have a project that you build from the command line with a makefile, then the Visual Studio development environment will not recognize your project. To open and build your project using Visual Studio, first create an empty project containing the appropriate build settings using the Makefile Project Wizard. You can then use this project to build your project from the Visual Studio development environment.
The project displays no files in Solution Explorer. The project specifies the build settings, which are reflected in the project's property page.
The output file that you specify in the project has no effect on the name that the build script generates; it declares only an intention.
Source: Creating a Makefile Project (VS2013)
On the menu: File->New->Project
On the dialog:
select Win32 Console Application,
enter Name ( like you did in the -o in unix) in the bottom,
and press OK
On the next dialog: Press next.
On the next dialog:
unmark Precompiled headers
mark Empty project
press Finish
Now find the Solution Explorer tree. You have Solution name and a project with the same name in it.
Right click on the project (not solution)
choose Add->Existing Item
and select your files, (you can copy them to the opened folder and then choose them)
press Add
Now you can try to compile.

How to compile a cpp to a dll in visual studio 2010 express

I have a cpp which depends on couple of headers in the same folder. I need to compile this cpp to a dll. How do I do it in visual studio 2010 expresS?
I found few articles on web for visual studio 2008 but I could not use it in 2010. Any pointers would be highly appreciated. Btw, I am a java programmer. CPP is all new to me, I am compiling some one else's cpp to dll.
Thanks,
Abi
Right-click on your project in the Solution Explorer, and select Properties.... Under Configuration Properties -> General there's an option called Configuration Type. If you change it to Dynamic Library (.dll), your project will generate a DLL when it is built.
As a start point, you can use "Create New Project from Existing Code" as described here - specify that you want a DLL project when prompted.
Once you have a project in place that encapsulates your CPP code file, you can find other info on specific project settings in MSDN, or post new questions as you need to.

problem with simple dll in c++

Hello
i do not use c++ but i try to make a simple dll in c++ by usin Microsoft visual studio 2008 this my steps
1-new project
2-select win32 and chose win32 project
3- from the win Application Wizard i chose Dll and in Additional Option i celect Empty Project
4-right click "Source Files" and add new item
5- chose c++ file(.cpp)
6- in this file i write this code
#include <windows.h>
__declspec(dllexport) int ss()
{
return 5;
}
7-Build the project >> Build Succeeded
but there is no dll file
what is the wrong ??
Thanks in advance.
Where are you checking for the .dll output? By default it outputs to the Solution (NOT Project) debug/release folder.
If you are new to .dll building in Visual Studio I would suggest starting a project in a similar manner but NOT selecting empty project, and selecting 'exports symbols'. By doing this Visual Studio will generate an example file that shows you a good notation for defining exports.
Before you compile make sure you set up the buildconfiguration to "Release" and you have to save the whole project somewhere before you compile, otherwise it's located in a temp-folder. After you saved it, compile it and look inside the projectfolder. There should be a folder named "bin" with subfolders. Look inside those subfolders and you should find your dll!

How can I compile binary?

I'm a .net developer by heart and usually write web applications. However I've been given the binary of a small project and I need to compile it (I think).
It is only two files: mfile.h and mfile.cpp. From looking at the code the .h file is a header file that contains constants and the cpp file is the actual codefile.
I created a new C++ makefile project in Visual Studio Pro 2008 and added these but when I try to build it just says Error 1 Error result -1 returned from ''. Project mfile
I honestly have never worked with this type of code before but I want to compile this and start learning. What exactly am I missing?
Wish you were running VS 6, in which case you'd just load the .cpp file, click "build", click "okay" when it says it's going to create a project for you, and off you go.
With VS 2008, you want to:
Move these files into a directory by themselves
Select File -> New -> Project from Existing code...
Accept "Visual C++ Project"
Select the directory where you put the file
Probably select "Console Application Project"
Accept the rest of the defaults (click "Finish").
Now you should be able to (finally) build your project.
Alternatively, you can compile from the command line. In the start menu go to "Microsoft Visual Studio 8.0" -> "Visual Studio Tools" and pick one of the command prompts. When it opens, use cd to switch to wherever you've stored the files. Type:
cl mfile.cpp
to compile.
Do not create a makefile project but a standard Console application project (empty). After the empty project is created, add the two files and hit F5. If there are no errors or missing dependencies, everything should compile and run.
Using the makefile project is not the right approach (for windows at least). You should start by using the wizard for a new C++ project. Add those files to the created solution and build.

How to compile different extension files as C++ in Visual Studio C++ 2010?

In my Visual Studio 2010 project I have files with .mm file extension, that need to be compiled as normal C++ files. Is there a way to make a build rule for new extensions or something like that? In VS 2008 there were options for that, but they are gone in 2010.
For an individual file: Right click on the file > Properties > Configuration Properties - General > Item Type : C/C++ compiler.
In general for a project: How to: Select the Files to Build, Walkthrough: Using MSBuild, Walkthrough: Creating an MSBuild Project File from Scratch.
You can set how the file will be compiled for any unknown file type by:
Right click on the file in your solution explorer
Click on properties on the file
Go to the General tab
Set exclude from build to: No
Set Item type: to C/C++ compiler
in vs2008 you can set in project properties (simply select extensions that should be treated as C++ via menu)
in vs2010 and vs2012 I've never been able to configure this properly, I tried all these walkthroughs, tutorials and tricks. They simply do not work as expected and my *.mm files are not compiled.