i tried to install my first program but it doesnt run. As the default program runs correctly. I created the new file as File>new>empty file and saved as .cpp but the program doesnt run. Ive matched the program from the book and the default one..
What is wrong
you can only have one main. By removing the Untitled.cpp file you will only have one file, main.cpp. you give your new file a name instead of taking the default name "Untitled.cpp". Or you can simply create an new project
Related
I'm trying to help my son with a Programming C++ for Engineers course. I got him set up with Xcode 13.1 on his iMac but I've never used it myself. That was working great until his first assignment that required writing output to a file. We created a new Command Line Tool project and then used the File->New->File... option to create an Empty file. After doing so, selecting that file and looking at the info on the right side of the window shows that the Full Path is pointing to the directory where his main.cpp file is. Yet, when running his code nothing was being written to the file. I had assumed that just referencing the file name in his code would cause it to use a local reference and look in the same directory as main.cpp. After much Googling I found a reference that said to go to Product->Scheme->Edit Scheme... then select the Options tab in the window that opens and change the Working Directory from "$(BUILT_PRODUCTS_DIR)" to the directory containing the main.cpp file. That got the programming working correctly. My questions are:
Is there a preference setting that would tell it to always use the current project directory so that we don't have to change this every time?
Where does "$(BUILT_PRODUCTS_DIR)" point to?
What should we be doing differently?
I have code blocks 17and i created a new project.
Clicked create new project
2.Console application
3.C++
4.Gave it a name and stored it in an empty folder
5.Created new file inside the project and wrote some code.
When i build, it builds without errors. When i run it, It always runs main.cpp by default. How do i execute other files without having to run main.cpp everytime.
It doesn't run main.cpp - it runs the main() function, which might be in any named .cpp file - a file with the name main.cpp is not special as far as Code::Blocks, or C++ in general, is concerned. But a Code::Blocks project can only have one main() function.
From the looks of it, you could delete the main.cpp file from the project or just add the int main() function into the file that you want and remove the one in main.cpp
You need to build a file before you run it so insted of giving only run give build&run option.
I am new to NetBeans (switched from Dev) and added a new main file to a project to try to test a few things out (clearly this is not acceptable in NetBeans). Now, even though I've deleted the extra main file, my builds keep failing and I am seeing "No rule to make target newmain.cpp', needed bybuild/Debug/MinGW-Windows/newmain.o'. Stop" ... so it seems like it's still looking for the extra main file even though I've deleted it. How do I stop this from happening?
UPDATE: found the file and removed it from the project correctly, but deleted the Makefile in the process. How do I recreate the Makefile?
I changed the name of an modified application to seperate it from the basic application. Lets say the .C file of the old application is "OldApplication.C" and of the new modified one is "NewApplication.C" Unfortunately, when trying to start the new modified application in terminal by typing "NewApplication" I get:
NewApplication: command not found
Two Question:
How can I make my new application executeable?
Can someone give me a brief overview about the files of a project/application and their functions?
greetings, streight
The mistake of this kind
make: * No rule to make target OldApplication.dep', needed byMake/linuxGccDPOpt/dependencies'. Stop.
often occurs in situation when the Makefile ceases to comply with the structure of the whole project.
In your case make script obviously trying to find the file that was renamed by you and therefore it fails with en error. I think that you should explore the structure of your Makefile and replace all the changed file names with its new versions.
Also you say the you are refused to launch your new executable, but what else could be expected since the project was not compiled?
I am working on figuring out how to use Xcode 4 to debug c++ projects.
I have basically copy pasted a working c++ executable that when compiled from the terminal ran fine.
However, i was thinking it might be nice to use Xcode for debugging. So I am trying to migrate the single .cpp file into Xcode as a command line tool.
I need to read in a file called numbers.txt (which I supply through a command line argument) which is located in my project directory, and then out put to a file (whose name I also specify as an argument.)
The problem I am running into is that the files that are supplied as command line arguments are failing to open.
ifstream in;
ofstream out;
in.open(argv[1]);
out.open(argv[2]);
I have checked to make sure that the arguments are being properly passed and are named correctly. The ifstream in is being supplied with `numbers.txt', which I want to open a text file that I already have.
However when I check to make sure the ifstream is open:
if(in.is_open() == false){
cerr << "Unable to open input file" << endl;
return 1;
}
I get the error.
I suspect this has something to do with how Xcode organizes the project.
my numbers.txt file is just sitting in the Xcode project folder, and I have only one .cpp class and one product, the executable.
anyone know what I am missing here?
The executable built by Xcode is in a different folder than the project. Passing in the name of the file without an absolute path before it will cause the executable to look for it in the wrong place, which is why it can't be found. Some of the possible solutions are to include the file as part of the build process (so it ends up in the same directory as the executable) or to pass the file to be opened by its absolute path. There are other ways to solve the problem, too, but hopefully that should be enough to get you started.
Old thread, but i have faced the same problem now, and it is easy to solve. Just copy the file in the build phase.
Here is an screenshot of the final result (note the destination, subpath and checkbox):