How can I get eclipse to run an open source file now?

I feel awkward asking this question, but for the last half hour I've been trying to figure out how to run a specific source file in eclipse without any luck.

I created a C ++ project, then created a source folder and a C ++ source file. This file works fine, but when I added the second file to the folder, it does not seem to start. I know this because it displays "hello world", which was in the first source file. The strange thing is, if I have an error in my second file, then I get errors, but after I fix them, I still get only the output of the first file.

Is it possible to run the source file that is currently open in eclipse (sort of like with Java)? My goal is to create a new source file for each exercise of the C ++ book that I work in, and get them to work independently without having to create new projects for each exercise.

+4
source share
2 answers

I just finished creating a C ++ online course for lynda.com (info here: http://cpp.bw.org/ ) using Eclipse because it is cross-platform and people can follow the exercises on different platforms. Here is how I solved this problem:

First understand how Eclipse CDT works - all the files in the project are collected and linked to each other. This means that you can only have one main() in the whole project. Thus, creating multiple exercise files in one project will not work. Here's a simple solution:

Create a new project and select "General" β†’ "Project" for the project type. Within this general project, merge all exercise files with it. (Right-click on the project, choose New> Folder, click Advanced in the dialog, select Link to Alternate Location.) If there are subdirectories in the directory, that’s fine - it works great. This will be an easily accessible repository for you, and it will not be compiled.

Now create another project and select the C ++ project for the type of project (I call it "Work"). Now, for each lesson, copy the file (or files) that you will work with from the general project to the Work Project. Do exercises, play with files, etc. You still have the original files because you are working on copies, so feel free to make a lot of mistakes.

When you are finished with each exercise, simply delete the file from the "Work" and run "Clear" in the "Project" menu (this step is especially important for Windows using MingW) before copying the next set of exercise files to the "Work".

I found that this workflow works very well for this purpose.

//Bill

+5
source

You may need to create a new project for each exercise or view the launch configuration options and specify which file you want to run. Click the small down arrow next to the green run button to create or edit a run configuration.

+1
source

Source: https://habr.com/ru/post/1410913/


All Articles