Readme file to C++ project - c++

I have a C++ project in Visual Studio. I want to add a readme file to it and that it will be copied to the build folder with exe. Is there any built-in feature in Visual Studio 2010 and 2013?

At project properties (Project menu --> [Project name] properties... menu or ALT+F7) you can find the Post-Build Event tab (Configuration properties --> Build events --> Post-Build Event). Here you can write your macro which copies the readme file to the build folder. You can use the build-in macros to use special folder (i.e. build folder):
https://msdn.microsoft.com/en-us/library/c02as0cs.aspx
A possible solution: copy $(ProjectDir)\ReadMe.txt $(TargetDir)

The easyest way to do this, is right-clicking the file in the solution explorer, choose properties, and there set the "Copy to output directory" option.
Update
As Tanya pointed out this option is only visible in C# projects, but not in C++. The option exists though, only not exposed to the UI. See the answers to this question:
Automatic copy files to output during application building

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.

Where is the "per file" Custom Build Step in Visual Studio 2013?

I have converted my C++ project from Visual Studio 2010 to the 2013 Community edition.
With previous versions I could always right click on a source file and edit a Custom Build step in the properties. Now I can't find the equivalent in VS2013.
The converted project has a Custom Build Step and runs it, but where do I edit it ?
When I open the raw 2013 .vcxproj file, I can see my custom build step as
<CustomBuild Include="foo.h.in">
...
</CustomBuild>
But I don't really want to keep editing my project with a text editor...
Just as harper described. One more thing to add - in VS 2013 and higher they renamed file specific Custom Build Step to Custom Build Tool and its not shown by default. To show it change the Configuration Properties -> General -> Item Type to Custom Build Tool. Apply the changes and 'Custom Build Tool' sub menu will appear.
You find it in the project property pages. Navigate to Configuration Properties -> Custom Build Step -> General.
I had sometimes strange results when converting old projects. I use to create new projects and add the files nowadays what gives better results.

Porting several dependent C++ makefile projects into MSVC

I have several projects which depend on each other. For example, when I install them I do this:
Project1:
/configure & make & make install
Project2:
/configure & make & make install
Such that "Project2" depends on some libraries of "Project1". I want to create an MSVC project for Project2, and start working with it, and changing it (and compiling it inside). How can I do this?
Also, how different is this to be done in linux with Eclips (when you don't have admin permission and can't do 'make install')?
You can create project dependence in Visual Studio.
To assign dependencies to projects
In Solution Explorer, select a project.
On the Project menu, choose Project Dependencies.
The Project Dependencies dialog box opens.
On the Dependencies tab, select a project from the Project drop-down
menu.
In the Depends on field, select the check box of any other project
that must build before this project does.
You can read more about it here
Visual Studio is your usual clickfest, but you can define project dependencies.
Define one project per module, then go to the solution properties tab and, for each project, select the checkboxes that inform the IDE that this project depends on a set of other projects.
The IDE will then sort and build them in the appropriate order.

How to create a DLL with SWIG from Visual Studio 2010

I've been trying for weeks to get Microsoft Visual Studio 2010 to create a DLL for me with SWIG. If you have already gone through this process, would you be so kind as to give a thoughtful step-by-step process explanation? I've looked everywhere online and have spent many many hours trying to do this; but all of the tutorials that I have found are outdated or badly explained.
I have succeeded in going through this process with cygwin; but as some of you know, a cygwin DLL is not very practical.
As a result, I have .i, .cpp, and .h files that I know can create a DLL together. I just need to know how to do this with Visual Studio C++ 2010. The language that I am targeting is Python.
Step-by-step instructions. This assumes you have the source and are building a single DLL extension that links the source directly into it. I didn't go back through it after creating a working project, so I may have missed something. Comment on this post if you get stuck on a step. If you have an existing DLL and want to create a Python extension DLL that wraps it, this steps are slightly different. If you need help with that comment on this post and I will extend it.
Edit 8/19/2012: If starting with a C example, don't use -c++ in step 13 and use .c instead of .cxx for the wrap file extension in steps 14 and 19.
Start Visual Studio 2010
File, New, Project from Existing Code...
Select "Visual C++" project type and click Next.
Enter project file location where the .cpp/.h/.i files are.
For Project Name, choose the name used in %module statement in your .i file (case matters).
Select project type "Dynamically linked library (DLL) project" and click Next.
Add to Include search paths the path to the Python.h file, usually something like "C:\Python27\include" and click Next.
Click Finish.
Right-click the Project in Solution Explorer, Add, Existing Item..., and select your .i file.
Right-click the .i file, Properties, and select Configuration "All Configurations".
Change Item Type to "Custom Build Tool" and click Apply.
Select "Custom Build Tool" in Properties (it will appear after Apply above).
Enter Command Line of "swig -c++ -python -outdir $(Outdir) %(Identity)" (this assumes SWIG is in your path and redirects the generated .py file to the Debug or Release directory as needed).
In Outputs enter "%(Filename)_wrap.cxx;$(Outdir)%(Filename).py".
Click OK.
Right-click the .i file, and select Compile.
Right-click the project, Add, New Filter, name it "Generated Files".
Right-click "Generated Files", click Properties, and set "SCC Files" to "False" (if you use source-control, this prevents VS2010 trying to check in the generated files in this filter).
Right-click "Generated Files", Add, Exiting Item and select the _wrap.cxx file that was generated by the compile.
Right-click the project, Properties.
Select Configuration "All Configurations".
Select Configuration Properties, Linker, General, Additional Library Directories and add the path to the python libraries, typically "C:\Python27\libs".
Select Configuration Properties, General and set TargetName to "_$(ProjectName)".
Set Target Extension to ".pyd".
Build the "Release" version of the project. You can't build the Debug version unless you build a debug version of Python itself.
Open a console, go to the Release directory of the project, run python, import your module, and call a function!

Visual Studio C++ project management. How do I handle non-code files in a project?

I have a project in a c++ solution. For that project, I have some config files that I would like to manage from within the project and when I build the project, have those config files added to the executable build path in the proper directory structure.
Example:
test.exe references config/myconfig.txt
Is there a way to setup myconfig.txt and my project so when I build test.exe, I get
/
as well as
//config/config.txt
so when I run test, all paths stay in the proper order without me having to go in and manually create those directories.
I'm not sure I'm making sense here, but maybe one of you will understand where I'm going.
You could use pre-build events to create the directories and copy the files.
In Visual Studio's Solution Explorer, you can right-click on the non-code files, select "Properties" and set the "Copy To Output Directory" property.
This creates a rule in the build file to (1) include the file, and (2) to copy that file as part of the build process. In other words, it's possible to get this behavior without Visual Studio, but a little more work.