Building an EXE with Visual Studio 2013 - c++

I'm unclear on how to do this. All I can find on the internet is that you build and then the exe will automatically appear in the project file, but that is not the case for me. I just tried setting up an extremely basic C++ project with one main.cpp of this:
#include <iostream>
int main() {
std::cout << "Hey ho!" << std::endl;
}
It runs all nice and well in Visual Studio, but there is no EXE in the project. Am I doing something wrong? Also, for the record, this is the output I get when I build:
1>------ Build started: Project: ConsoleApplication1, Configuration: Release Win32 ------
1> main.cpp
1> Generating code
1> Finished generating code
1> ConsoleApplication1.vcxproj -> c:\users\oysi\documents\visual studio 2013\Projects\ConsoleApplication1\Release\ConsoleApplication1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Try F5, it will build and run your project. If you put a breakpoint at the closing bracket (}) of main, you'll even see your output in the console.
The .exe won't be added to the project, but it will be created in the output directory. The output you copied here actually tells you, where you can find the .exe:
c:\users\oysi\documents\visual studio 2013\Projects\ConsoleApplication1\Release\ConsoleApplication1.exe

As Visual tells you, you should look for .EXE file in this directory:
c:\users\<username>\documents\visual studio 2013\Projects\ConsoleApplication1\Release\ConsoleApplication1.exe

Related

How to get Modules to work in VS2019 16.8?

I'm trying to convert my program to modules. I'm using MSVS 19 Community Edition version 16.8 (also tried with MSVS19CE Version 16.9.01 Preview)
Each .ixx IDF I write compiles fine when compiled indiviually, (with "import"'s and its usage commented out),
Build started...
1>------ Build started: Project: myCare, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>Compiling...
1>DB.ixx
1>Compiling...
1>HS.ixx
1>pch.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
But when I introduce the commented out imports, suddenly VS can't find the modules it just previously compiled beautifully.
Build started...
1>------ Build started: Project: myCare, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>Compiling...
1>HS.ixx <<<<----- Compiled without errors
1>Compiling...
...
1>ComplexComboBox.ixx
1>D:\Dev\myCare\Modules\ComplexComboBox.ixx(289,1): error C2230: could not find module 'HS'
1>D:\Dev\myCare\Modules\ComplexComboBox.ixx(289,1): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\CL.exe'
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>Done building project "myCare.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
error C2230: could not find module 'HS'
error C2230: could not find module 'Aui'
error C2230: could not find module 'Ctrl.ListCtrl'
Any hints? Every module has the structure like this (and has the file extension .ixx)
module;
#include "Defines.h"
#include <any>
#include <bitset>
...
export module HS;
namespace HS
{
export enum class Comms { None = 0, Port = 1, Timeout = 2, Authority = 3, Security = 4 };
export auto CommsAuthority(const AuthorityType newValue)->void;
export auto CommsAuthority(void)->AuthorityType;
(Not everything in here is exported)
...
}
module :private;
auto HS::CommsAuthority(const AuthorityType newValue)->void
{
...
}
auto HS::CommsAuthority(void)->AuthorityType
{
...
}
...
This seems to be a bug with the way visual studio currently handles modules imported by other modules. Essentially when each module compiles it creates a <module_file_name>.ixx.ifc file. This is detected perfectly fine when the module is imported into a cpp file but not when importing to a module. removing the .ixx from the filename will import correctly whether importing to another module or a cpp file though.
I solved this in 1 of my own projects through the project properties(the required options are only available in the preview version of visual studio at the moment though).
So you first need to set Module File name to $(IntDir)%(Filename).ifc in C/C++->Output Files
Then set Additional BMI Directories to $(IntDir) in C/C++->General.
Visual studio puts all the intermediate module stuff in the intermediate directory by default but if you'd rather have all your intermediate module things in a separate folder you can set Module Dependencies File in C/C++->Advanced to wherever you want and then update the $(IntDir) bits above to the new location.

My C++ project can't find the .exe

I haven't been coding in some time and I wanted to open up a new project to wipe of the rust.
I go to File New... Project
I press on "Visual C++"
Select an empty project and name it "test"
In the solution explorer I right click on Source Files
I select Add New Item...
I select the C++ file (.cpp) and name it main.cpp (no reason)
I write this simple piece of code right here:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
I go to Build Build Solution (and here start the problems...)
When it builds it shows this Output:
1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
1>Done building project "Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It also goes to the Error List and shows this error:LNK1104
I have no idea what's the problem here because this exact same way always worked and now it suddenly doesn't? Can anybody explain me what am I doing here? I searched all over the neat and found people with similar problems but didn't really understand the solutions.
I had similar problem. Try Properties -> Configuration properties -> Linker -> System -> Set the SubSystem to 'Windows (/SUBSYSTEM:WINDOWS)'.
It helped to me.

C++ Error for file_size() which belongs to Boost Filesystem

My IDE is MS Visual Studio C++ 2013, and I use Boost Library for Filesystem Operations.
I have written this code:
// BoostFileSystem.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <boost\filesystem.hpp>
using namespace boost::filesystem;
using namespace std;
int main()
{
cout << "File Size: " << endl;
cout << file_size("as.jpg");
return 0;
}
It throws error. The error is that:
1>------ Build started: Project: BoostFileSystem, Configuration: Debug Win32 ------
1> BoostFileSystem.cpp
1> LINK : C:\...\visual studio 2013\Projects\BoostFileSystem\Debug\BoostFileSystem.exe not found or not built by the last incremental link; performing full link
1> BoostFileSystem.vcxproj -> C:\..\documents\visual studio 2013\Projects\BoostFileSystem\Debug\BoostFileSystem.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
'as.jpg' is also included in the Resources folder. When I remove this line:
file_size("as.jpg");
The error is not thrown. Also bear in mind that the compiler reports no failure.
What is the problem? I really cannot figure it out.
Because when I remove file_size() line, the program works fully and also prints the text on the screen ("File Size:"). While when run it as-is, the compiler throws no error, but no text (even the line before the file_size()) is not printer and in the console the following is printed (which is also outputed to the error-area as already pasted above):
UPDATED:
Here is the error shown in the console window:
The system cannot find the file C:\Users\Ali\do
ts\BoostFileSystem\Debug\BoostFileSystem.exe.
The problem is solved. I post it for future visitors.
The problem is with incremental linking enabled in MS-Visual Studio C++. If disable it, then the program works.
Go to the properties of the project, then to the Linker, General and Disable the Incremental Linking.

C++ multiple files with Microsoft Visual C++ 2010 Express

I am brand new to C++. I have a question on how to run a C++ program that contains multiple files. I am using Microsoft Visual C++ 2010 Express as the IDE. I don't know why, but the program won't run. I am pretty sure that my coding is all right. How can I fix this? Any help will be greatly appreciated. Below is my code in the two files (the project name is PracticeConsoleMultipleFiles and I created the project as a Win32 Console Application):
NewFile1.cpp:
int add(int x, int y){
return x + y;
}
Main.cpp:
#include "stdafx.h"
#include <iostream>
int add(int x, int y);
int main(){
using namespace std;
cout << "The sum of 9 and 9 is " << add(9, 9) << endl;
return 0;
}
When I build my program, I get this:
1>------ Build started: Project: PracticeConsoleMultipleFiles, Configuration: Debug
Win32 ------
1> NewFile1.cpp
1>c:\users\timothylee\documents\visual studio 2010 \projects\main\practiceconsolemultiplefiles\newfile1.cpp(4): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1> Main.cpp
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
and when I run it, it says that:
This project is out of date: PracticeConsoleMultipleFiles - Debug Win32
I recommend that you, as a beginner to c++, start off with a blank project when using visual studio, this will not place the code including stdafx.h in your main.cpp which should solve the error you are getting

Building a C++ project in Visual Studio doesn't create any files

I recently decided to start learning Visual Studio so that it replaces my need for CodeBlocks and MinGW for C++ programming.
So, today I made a new Win32 C++ Console Application, wrote down this code in a new .cpp file
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << endl;
return 0;
}
and compiled it. The log said
1>------ Build started: Project: CPP_CONSOLE_TEST, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(357,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
and I though my code was compiled and my .exe was created.
Then, upon trying to debug my program, Visual Studio said:
Unable to start program 'C:\Users\XYZ\Documents\Visual Studio 2013\Projects\CPP_CONSOLE_TEST\Debug\CPP_CONSOLE_TEST.exe'. The system cannot find the file specified.
I then opened the Debug folder of the project and it was completely empty...
I've been searching around Google for some time and I even tried to "Repair" my Visual Studio build with no results. Any help?
Quick edit: Just tried compiling a C# app, just to see if the IDE itself was the problem. It compiled and ran just fine, so it's some issue with the Visual C++ compiler and its settings...
Turns out I hadn't added the source file to the Project... :|
Visual Studio, has its own vision of c++ projects. By default, it needs a #include "stdafx.h" on top of your cpp file, with the associated stdafx.h and stdafx.cpp files.
Then, in a c++ visual studio project, the real definition of the main function is int _tmain(int argc, _TCHAR* argv[]). But it should work with your definition.
Why don't you try to use Serge Rogatch's solution?
There is a bug in Visual Studio which leads to problems when project has long path.