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

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).

Related

Understanding how to compile C++ project

I'm new to coding and Visual Studio. I know and understand how to create, save and compile a new C++ project in Visual Studio. I understand that a new VS project creates a solution file in the directory which then I can use to open the project, etc.
What I don't understand is how to compile a C++ project which doesn't have a VS solution file. I mean, do I have to manually create a project and import files and then build it?
Please take this GitHub project as an example. Under information, it clearly states the following:
Building
To build a static library (./lib/ompeval.a) on Unix systems, use make.
To enable -msse4.1 switch, use make SSE4=1. Run tests with ./test. For
Windows there's currently no build files, so you will have to compile
everything manually. The code has been tested with MSVC2013, TDM-GCC
5.1.0 and MinGW64 6.1, Clang 3.8.1 on Cygwin, and g++ 4.8 on Debian.
Now, what I don't understand is how do I build this project in my VS software so that I can successfully run it? Any help would be appreciated. Thank you.
As you said it, create a new project in Visual Studio and just import the source and header files. Looking at the makefile, there doesn't seem to be any pre or post build events so you can import the files and compile them right away (as long as the code is platform compatible ofc).
You may have to create multiple projects. One for the static library and one for the test files, since Visual Studio projects usually have one output type only. Mostly one of the presets: dynamic library (dll), static library (lib) or executable (exe).

Setting up C++ include settings for a large library such as Paraview and QT in Eclipse

I have an application where I am compiling against the libraries Qt (5.11) and Paraview (5.6). I am developing in C++ and I am also coding in Eclipse.
Yes, I am aware that Paraview is more of an application then a library. However, I will be using it as a library to intergrate Paraview in my application in order to visualize some data. I could use QT creator and that would take care of the QT library. However, I am not very familiar with QT creator as an IDE and my entire workflow has been based around eclipse. For this, I would like to utilize components that I am familiar with.
Now, as many of you know, the QT library is large, very large. So is Paraview. I could create a search path for each folder containing the header files I need in the C++ include settings. If I go in this direction, then my library search path will be long, very long. Also, there might be a situation where I need to change computers (for whatever reason), I would then need to edit the search paths for the new computer and that will take time.I had thought that I could only include the paths to the include files that I needed. And I have started to do that. However, when I compile my application, I noticed that the libraries would use include files that are located in a directory that Eclipse is not even searching in. At the end of the day, I would need to include all of the directories to which the header files are stored in.
I was wondering if there might be a better method to reference all of the files that my project needs? Both come with make files (I believe that Qt includes a QMake file?). Is there a simpler method to include all of the files instead of editing the C++ include path for eclipse? I did see an option for QMake in Eclipse, is there anything that I can do with that feature to compile to QT library with my application?
Thank you and any feedback is appreciated. Also, feel free to suggest edits or clarification so that my description is clear.
Note some good practices when working with eclipse and qt or other large library.
Include the directories with a headers
If you use option "Generate Makefile automatically", add group include path with GUI Eclipse:
copy the directories with a headers (via system explorer);
go to project properties/C/C++Build/Settings/Tool Settings/GCC C++
Compiler/Includes.
paste directories (Ctrl+V) into "Include paths" list.
If you are using a qt-eclipse-integration plugin, you can add folders via the Discovered scanner configuration. You can find it if open: project properties/C/C++ Include Paths and Symbols/Add Contributed...
Create new project
if you already have a customized project, you can use it as a template:
make a copy of the customized project and name "mytempate";
delete all files from "mytempate".
When you want to create a new project, copy the template and specify (in the copy dialog) the path where the source codes are located.
Now you have a finished new project with settings and code.
Change computers
Use one of the ways:
1. Export C/C++ project settings for use in another workspace via project properties/C/C++ General/Paths and symbols/Includes/Export Settings...
2. Pack in the archive eclipse and workspace and copy your another computer.

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

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.

C++ Code::Blocks making libraries on Windows

So I'm using Code::Blocks right now as my IDE on Windows 10 and I made a small library with one little function.
Code::Blocks made me a .a file.
I then made a little test project that uses the library. Added it to my project build options in Linker Settings, and added its directory to my search directories. Great.
I can see the header file I made for the library so that's working.
I then try to use the function and I'm getting an 'undefined reference' for that function call.
So..I'm going to assume Windows doesn't understand how to load libraries with the '.a' extension? I believe Windows uses .lib files instead but I'm not sure how else I'm supposed to compile a .lib file in Code::Blocks as there's no template for it.
I am extremely new to Code::Blocks and making libraries in general.
Solved. Problem was when renaming the file from "main.c" to "main.cpp", Code::Blocks does not automatically change the compiler variable.
This was done by going into the file properties in the IDE and changing the variable from "CC" to "CPP".

Netbeans C++ using MinGW and the libnoise library

Using netbeans 7.2 and the most recent version of MinGW (using installer) I can't use the libnoise library. I am properly including the header files, the auto completion confirms this, however the library is simply not working. There is a .lib file and a .dll. I have tried every possible combination of adding them under project > properties > Build > Linker as well as putting the .dll in the base project directory. Despite all this I am still getting undefined reference errors whenever I try and run the code. Does anyone know what to do?
I know that it is possible to link import library files (*.lib) with MinGW, but I still suggest to recompile libnoise.
With the current Makefile, this is not very easy and may break. Thus I've written a CMake script, which doesn't only work on Windows, but should work on all CMake supported platforms. In addition to this, I've cleaned up the directory structure. The code itself hasn't been touched and when you build a library it should essentially be the same as the current one.
libnoise on GitHub
After you've built your shared library, you'll have a libnoise.dll.a and libnoise.dll file. You then add libnoise.dll.a to the linking settings and put the DLL itself next to the binary, or in the working directory.
You have to link the lib file (= adding it to linker libraries) and put the dll to
<project root>/dist/<...>/
(where your exe is put to). There's no need to add the dll to linker too.
Can you please post the error message you get?