How to create a C++ project in Eclipse CDT using existing source files and an existing CMakeLists.txt? - c++

The title says it all: I have source files and a CMakeLists.txt for an existing C++ project. Now I want to create a project in Eclipse CDT using those files.
I want to be able to build the project with the "build" button from within Eclipse once I'm done, and I want to be able to use GDB.
I've used the CMake option to create Eclipse projects before, but it didn't always work flawlessly and I was told the CMake generator for Eclipse is supposedly outdated.
I know I could just create an empty project and then copy the source files into it, but what about the CMakeLists.txt? I want Eclipse to know how to build the project.
I'm new to Eclipse and there are like fifty ways to start a new project with or without existing source files, so some guidance would be greatly appreciated.

Related

How can I get "go to definition" working in a JUCE project?

I'm trying to get "go to definition" working for a JUCE project created with Projucer. I've tried both CLion and Visual Studio Code, but they can't seem to find definitions that live in the JUCE libraries.
I'm on Ubuntu. Is there a blessed path for this? I'm normally a vim user, but I'm willing to try any IDE.
I've just figured this out!
In VS Code go View and Command Palette and type C/C++: Edit Configurations (UI) which will take to the IntelliSense Configurations page. Under Include path, on a new line, specify the path to JUCE e.g. ~/JUCE/**.
Note: The two stars are needed to tell VS Code to look through subdirectories.
This will create a hidden folder .vscode in your project folder with this configuration.
You will need to repeat these steps for each project you make.
Definitions and code completion should now work.
To compile your code, in your project folder go Builds then LinuxMakefile and in a terminal run the command make. Finally, go to the builds folder and run your project ./exampleProject.
You need to add the JUCE/modules folder to your search path, not the top-level JUCE/ folder!
If you're using the Projucer, you'll also need to add the JuceLibrarySource/ folder to your search path.
What I ended up doing was using FRUT to convert my project from a Projucer project to a CMake project. CLion was able to understand the CMake project, and thus, the "go to definition" and autocomplete features started working.

Adding files to a Netbeans C++ project

Background
I was working on a C++ project on a Windows machine, building using a makefile, and editing with Notepad++. I then decided to switch to a modern IDE, partly so that I wouldn't have to keep editing the makefile, so I installed Netbeans (first time I have used this IDE). When I created the project, I specified my existing makefile. All is well, and I can edit and build my project.
There were a couple of source files in the directory which were not mentioned in the makefile. However, they do show up in the file list in grey:
Problem
I can't for the life of me figure out how to add those grey files to the build. Do I still have to edit the makefile? Isn't the IDE supposed to manage this kind of thing?
No, Netbeans won't change your custom Makefile. If I were in your shoes, I'd start a new project and add the source files manually, and after that write any custom build steps you might require.

Importing c++ projects to eclipse

I use eclipse Neon from a ubuntu 15.04 virtual box.
I want to run medical image reconstruction framework gadgetron from https://github.com/gadgetron/gadgetron. I downloaded zip file and extracted the gadgetron code zip folder into eclipse workspace. The folder structure shown below:
Through menu New -> Makefile project with Existing Code, I imported the gadgetron code into eclipse IDE. The eclipse screen looks like this.
When I try to build the project, I get an error make:*** No rule to make targe 'all'. Stop.
How can I build and run this project in eclipse IDE?
Check the README of the project. You imported as an project with an existing makefile. Eclipse looks for the Makefile in the root directory of the project and in this case simply couldn't find one. You can either tell Eclipse to use a specific Makefile or create one in the root of the project.
Edited: Adjusted answer to show final solution.

Eclipse CDT Kepler Importing Makefile project

I would love to import a Makefile project from Eclipse, and have all the different includes path that the compiler uses to create correctly my Eclipse project.
Unfortunately, those path, specified on the command line by a "-I" don't show up in Project Explorer and I have to add them by hand.
I am currently importing the project using the standard "Import project from Makefile" built in Eclipse.
If I'm not wrong there was an autodiscovery option in older versions of Eclipse, but it's not there anymore.
How do you do for having all your include paths set up without too much hassle?
The trick is NOT to use
File->New->Makefile Project with Existing Code
but to use
File->New->C++ Project
and then to select
Makefile project->Empty project.
After you set up such a dummy project, you simply copy your existing source to that project directory, hit F5 (i.e. Refresh) and change the build command to use your Makefile.
I was able to get this to work using Luna. I imported using File->New->C++->Makefile Project with Existing Code.
Prior to launching eclipse, you have to be sure to source any files that set required environment variables.
I did have some build options which were not the standard all and clean, so I had to add those configurations individually.
source files to setup your environment.
Launch Eclipse
Import C++ Makefile project
Setup Build options.
Click the hammer.

How to start a CodeBlocks project from external code and Makefile?

I have C++ code that depends on boost and other libraries, and therefore this code has a makefile that invokes boost.
I am now trying to start developing this code in CodeBlocks in linux, so in order to do that I have two basic questions:
(1) How can I import the code into CodeBlocks as a CodeBlocks new project? This seems to be a good rec: http://www.programmingforums.org/thread44976.html
(2) How do I invoke the makefile with CodeBlocks instead of CodeBlocks trying to compile the code (which would fail since CodeBlocks do not know that it needs to invoke boost)?
How can I import the code into codeblocks as a codeblocks new project?
File > New > Project > Empty project
Create the project, then:
right click on the project name on the "Projects" pane;
add files recursively.
I recommend that you create Code::Blocks project new project at the top-level of your source (and not e.g. in a dedicated ~/codeblocks directory), or else it will show long file paths.
How do I invoke the makefile with codeblocks instead of codeblocks trying to compile the code (which would fail since codeblocks do not know that it needs to invoke boost)?
Asked at: Is it possible to use an existing Makefile to build a project in Code::Blocks?. For quick reference, the solution is to go to Project > Properties and toggle on the option This is a custom Makefile. Further options can be specified from the same window.
Most projects can be compiled without a makefile, so just include files, and if you need an extra library include that in a project. If your project uses header-only boost libraries and you have packet installed libboost-dev (this is on my Debian) then it is included automatically. Else just use the proper library name in settings (I can't remember if you need to append l to the name).