"launching 'project' has encountered .." , project file does not exist - c++

I wanted to write 'hello world' in eclipse c++, but it does not work
I go to Run configurations, what config options for c++ programs should i give?
I know I don't care about 'debug' - only 'release', but how to do that?

Here is what I did:
File->New->C++ Project
You will get a pop up window. Type the name of the project you want. Then, below it says executable and inside this folder, I have (by default I guess) Empty Project.
Then click Next and Finish.
Now the project appears in the left column of Eclipse. I right click it and select New->File and name it main.cpp
The main window of Eclipse opens the file main.cpp and I write inside:
#include <iostream>
int main() {
std::cout << "Hello Erjan\n" << std::endl;
return 0;
}
Then I click on Build, it's the hammer icon in the middle of the toolbar. The code compiles and we are ready to launch it!
So, click on Run icon (3 positions right of the Build icon) and you should see the output in the console.

The first step, create new project and try proper toolchains.
Second step, Project >> build project.
Third step, right click on new executive file and run or debug it.

Related

Visual Studio - C++ New File Default Code

Hey everyone I have a comfort problem is Visual Studio 2017 (I use 2017 because of school requirement).
Always when I start a new C++ Project or C++ File I get the default code:
// ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
It's very annoying for me to delete it every time and I'll be happy to know how to remove the default code. I searched the Internet and Microsoft MSDN and I didn't find any solution. Thank you for your help, this website helps me a lot!
There are two methods to create a empty project.
1.1 Create a project.
1.2 Edit the project until it is ready to be exported as a template. For example, you might want to edit code files to indicate where parameter replacement should take place. See How to: Substitute parameters in a template.
1.3 On the Project menu, choose Export Template.
The Export Template Wizard opens.
1.4 On the Choose Template Type page, select Project Template. Select the project you want to export to a template, and then choose Next.
1.5 On the Select Template Options page, enter a name and optional description, icon, and preview image for your template. These items will appear in the dialog box where you create a new project. Choose Finish.
You could use Windows Desktop Wizard.
Then select Empty Project.

compile single c++ source file in 1 project in visual studio

i know a lot of people asked this question, but i can't find how to do it. Is there
a way to build only one source file in visual studio 2017? without new project, i'm learning c++, so i can't make huge thing now, just focus to code(now i'm learn data structure and algorithm),most of my exercise is about <200 code lines, so it great to compile new file without whole project, sometimes i need a few lines of code to test my algorithm,please help me, thanks all you guy, because v.s is very good ide so i want to stick with it.
If you just have one file and want to build it without waiting 1-2 minutes for the IDE to pop up,
Find the Developer Command Prompt in your list of applications - it is under the Visual Studio directory in the Application menu.
cd /d to your directory. cd will take you here if you are on the same drive as visual studio. If you are on a different drive, use cd /d.
Use your favourite editor (notepad, vim, geany, notepad++, nano, microemacs etc) to create the file.
cl sourcefile
Run the excutable.
Unlike what visual studio does, you executable will now be in the same directory as your source. Editors like geany have a build button (the brick icon). All you need to do is fill in how to build: in this case, the cl command.
If you want a one file project, just follow these steps.
Create New Project - File -> New -> Project
Fill in filename, select Win32 Console Application. Note the directory - if it is not where you want it, change it. Click OK
Application Wizard pops up, click Next
Application settings - select Empty project, click Finish
Open Solution Explorer. Right click Source Files. Menu pops up, select Add -> New Item
Add new item dialog pops up, fill in your filename.
If you don't know how to create a new project and a new solution, it will be good to learn those basic concepts and use them to write, test, and debug your code.
You can use one Visual Studio project to do all the learning.
Let's say you want to test "algorithm 1". Then,
Create a header file for it and a source file for it -- call them "test-algorithm-1.hpp" and "test-algorithm-1.cpp".
Add them to the project.
#include the header file in the main .cpp file of the project.
Call the function to test "algorithm 1" from main.
#include "test-algorithm-1.hpp"
int main()
{
test_algorithm_1();
}
When you are ready for testing "algorithm 2", repeat the above steps. The main .cpp file can now be.
#include "test-algorithm-1.hpp"
#include "test-algorithm-2.hpp"
int main()
{
test_algorithm_1();
test_algorithm_2();
}
If you want to avoid testing "algorithm 1" while testing "algorithm 2", simply comment out the corresponding line in main.
int main()
{
// test_algorithm_1();
test_algorithm_2();
}
On the source file you don't want to be included in the project, simply right click, select Properties. There you will find in General a field 'Excluded From Build'. Type true/yes there and the source file will be deactivated.

Code::Block not creating a Debug Build?

I have had this problem with Code::Blocks that when my project is still overly small (even 10 lines long), and I go to build "debug", the file will not be created. It doesn't tell me this in Code::Blocks. Basically, I go to hit play, and it will ask me to build my project even though I had clicked the "build" button about 2 seconds before...
It works fine with release build, however...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello" << endl;
cout << "World!" << endl;
return 0;
}
Even a program as simple as that does work in release build, but not debug build (the file gets deleted).
Have I got something wrong with my settings? Note it was like this ever since I downloaded it, and I had no idea what was wrong (as it does debug build by default, so I didn't know I could use release build)
Anyone know?
Edit: yes, the file is part of a project file
Make sure you selected 'Console application' when creating the project instead of 'Empty Project'.
Also, when you create the project from new, make sure that the:-
'Create "Debug" configuration'
is enabled, and has valid paths showing etc.
On the previous dialog, where the new project tool asks for folder paths etc to put stuff, make sure you give it somewhere valid (that exists) etc, or make a new folder for it.
I've just built and run your bit of code as Debug and Release just fine, in C::B 16.01 on Windows. As a "Console" application. Using the defaults, other than I created a new folder for it all.
Regards.
DJB

Unable to launch program from the IDE

I have learned the basics of C++ but I have never used visual studio.
I would like to know why I get popup window that says "Unable to start program" and then lists a file path C:\folder\folder\folder\../../lib/Win32DB/ProjectNameDB.lib. (The message doesn't give me any more info, like 'the system cannot find the file specified' or anything like that.)
ProjectNameDB.lib exists, but not at that particular location. The project builds successfully, and the same path as above appears in the output after TargetPath =.
I have tried setting the project as startup, deleting .suo files and vcproj.user files, starting without debugging, and putting the location of ProjectName.lib in the Output, Library, Include, Reference Directories.
You can not start one *.lib but one *.exe. So build one EXE program you should use the below steps with Visual Statio 2013:
start vs2013;
choose File -> New -> Project;
choose Win32 Console Application, and write your project name, click OK;
click Next, click Finish;
Now, you can write "Hello World" in 'x.cpp'(here 'x' is your project name); the following code:
int main(int argc, _TCHAR* argv[])
{
printf("Hello Wrold!\n");
return 0;
}
save, build and start run it, it will print 'Hello World' in console.
exe file must have main function, but lib file is not necessary.
So... the problem was that the project was configured to run as a static library and not as an executable.
Properties -> Configuration Properties -> General

C++ Program in Xcode not outputting simple text file using outFile

I am running a program using this simple example code to output a text file. I am using Xcode and simply started a new C++ project from command line tools. For some reason the program does not output any file onto my Mac. Please help figure out why XCode will not output any file to my computer? Thanks!
#include <iostream>
#include <fstream>
using namespace std;
int main() {
double myNumber = 42.5;
fstream outfile("test.txt", fstream::out);
outfile << "The answer is almost " << myNumber << endl;
outfile.close();
}
Dang I can't believe I figured it out, it was an option in Xcode. So I clicked on the bar at the top of xcode near the stop button with the text (Project Name > My Mac 64-bit)
Then clicked edit scheme. The clicked on the options tab and clicked use custom working directory. Then selected a working directory. Now the text file appears!
As mentioned above, editing the scheme worked for me but getting to the scheme was different.
Use the Product Menu
Select the Scheme option
Select the Edit Scheme option
Click the Options Tab
Tick the "Working Directory" item
Click the small icon at the right end of the text box.
Select the directory
I also had the Run/Debug option selected in the left hand pane of the window.
To find the current working directory, in the project navigator, under the "Products" folder, right-click the product and choose "Show in Finder". In this directory you will also find the compiled code.
For example:
~/Library/Developer/Xcode/DerivedData/<project name>-gweghgfqkjkidjfhcgetdryechjz/Build/Products/Debug