Compile Single file in a project in netbeans - c++

I am using NetBeans Ide 8.2 on ubuntu 16
I am learning C and C++ programming hence the program i make are not related and when I try to create multiple file in a project the include multiple main() function which return error
error: multiple main function found
I want to create separate file for each program but I don't want to create separate project for all the program.
please suggest me a way & I am sorry for my language , I hope i am able to make you understand my problem.

To have multiple main files in a single Netbeans project:
Under the Projects tab in the left, double-click on your project to show its contents.
Double-click on the Source Files folder to show its contents
Right-click on the earlier main file (most-likely main.cpp) and select Properties.
Under the Item Configuration tab, check the Excluded from build option and click on Ok.
Right-click on the Source Files folder, select New and click on C++ Main File. This will create a new main file in the same project.
Now, when you build and run your project, it will compile the new main file, and the old one will be ignored.
Tip: It is a good idea to give unique names to the main files, to avoid name clashes.

Related

Visual Studio - why does stdafx.h gets embedded

I am Unix guy but for a project I need to code in VS 2015. Basically I need to write some GMOCK test cases for some C++ classes.
I first tried to start with a sample project so I selected File->New->Project->Win32->Win32 Console Application. The project did got created with a default name ConsoleApplication2.cpp having embedded statement -
#include "stdafx.h"
I found that if I delete this line the code fails to compile - Usually in Unix I create .h and .cpp files and then create its make file - my aim was to start a project - create some .h files first and then create its .cpp / GMOCK test cases and build then build all
Please let me know if there is an option in VS for same or the way to do so?
for the use of stdafx.h please see the link Here
If you want to add a header file and then the respective cpp file the you just need to go to the project in solution explorer at right side of your IDE. Right click and go for add. There you will get the option for header file and class both.
You can add from there and start writing your code for the test cases.
The steps to create an empty project without precompiled headers or additional default source files are:
After you select "Win32 Console Application" click "OK".
On the following dialog click "Next" to go to the Application Settings page.
Select the "Empty project" option and then click "Finish".
The "Empty project" option says:
This option creates a .vcxproj file based on the project name you specified but adds no files to it. Use this when you intend to supply all your own source files.

Why I can not see project files in Dev-C++?

When I create a project in Dev-C++ 5.9.2 save it and open it's *.dev file there is no file below it in the project tree but I can compile and run it!
I am using 5.9.2 and even I create Empty Project there is unsaved file that after compilation ask you to save it.
So be sure you are looking into tree Project and no Classes or Debug.
If you are looking into Project there should be +
However if it runs with black window and you still don't see project files post a screenshot please

I can't find the .exe file that qt-creator is supposed to be making

This is my first time using Qt-creator and I just got done coding my program and I want to put it on a USB and use it on a different computer but when I go to where my project is located at C:\Qt\Tools\QtCreator\bin\Calculator
I don't see any .exe files the only files i see are a
1 .pro file,
2. another .pro file,
3 .cpp file,
4 .cpp file,
5 .h file,
6 .ui file,.
I have built the project in Qt-creator and everything runs fine and my program works without any errors when i run it inside of Qt-creator. I do not have a debug or release folder like some people say I should.
so my question is, where can I find/create the .exe file for my project?
Most probably you have done a shadow build, that means you build isn't located at your source.
You can find out where your build is located when you open the Projects Mode in creator. On the top should be marked your project. Then select the Build & Run tab. Select your Kit and switch to the build settings. Locate the Build directory in the opened page.
That should be the location where your binaries are build.

Using eclipse CDT without creating a project

I am currently learning c++.My first language was python.I am used to coding in eclipse in pydev.
I learn a language by writing a lot of code snippets and use the debugger extensively to understand what is actually happening.
Now,I downloaded CDT for eclipse,since I am used to the interface.
But now,I am forced to create a project for every c++ file I write. I want a way to easily execute the files(very small,max 300 lines) in fast manner,and without creating new projects again and again.Any ideas?
Currently I use eclipse like a text editor,and use g++ for compiling the files.
I suggest you create one project containing all your files (assuming each one has its own main function), and inside this project, create one 'Build configuration' per program by using :
Project > Properties > C/C++ Build > Configuration > Manage... > New
To avoid multiple definition of main in each 'Build configuration', you will have to exclude each cpp file from the 'Build configurations' it doesn't belong to. For this, in the Navigator view :
Right click on the cpp file > Properties > C/C++ Build, and check 'Exclude from build' for each 'Build configuration' the source file does not belong to.
When everything compiles fine, you will be able to run or debug each program separately inside Eclipse by selecting the matching 'Build configuration'.
More info in this answer :
What files belong to a build target in CDT managed build?
I hope this will help!

Eclipse CDT: Import source / header files into my new project, without duplicating them

Im sure there is a very simple solution for this.
I have a bunch of .cpp / .h files from a project, say in directory ~/files
On the other hand, I want to create a c++ project using eclipse to work on those files, so I put my workspace on ~/wherever. Then I create a c++ project: ~/wherever/project, and include the source files (located in /~files).
The problem i'm having is that files are now duplicated in ~/wherever/project, and I would like to avoid that, specially so I know which copy of the file to commit.
Is this possible? Im sure it is, but cant get it.
Thanks in advance.
You could try:
creating the project directly above the ~/files (which is not very clean, given the location of the sources in your home dir)
using a linked folder
importing existing sources in your project: details all the options (when your sources are also managed by a VCS like CVS, or when your sources are not managed)
Create a file or folder in your project as per normal (choose File->New->Folder), give it a name, and click on the Advanced button. This reveals a file-choose field where you can browse for the resource you want to "virtually" include in the project. Click Okay and the file/folder you named is now linked outside of the project.