Using ITK with xcode - c++

I am working on an xcode project that requires me to use ITK (a c++ library), I have went through with the installation of ITK, by doing
ccmake InsightToolkit-4.13.1
and then configuring and generating the files, then runing
make
make install
but I do not know how to import the library into the xcode project, where I get the following error every time I try building it:
'itkImage.h' image file not found
I would like to know how could I import it and share it with other people on different computers.

The #include directive comes with two flavors:
With quotes (#include "file.h")
With ankle brackets (#include <file.h>)
The first usually refers to files relative to your project directory. The second is for system libraries.
You can influence the search path in the project setting:
double-click on the project in the project explorer
Click on Build settings
Click on your target
Click on All to view also hidden options
In the section Search Paths you can then update the header search path to include the absolute path of you rlibrary headers. Attention: you have to do this for the Debug and for the Release builds:
This will solve the error that you have reported.
Remark: be careful, because after this is solved, you could experience some other issues related to the good use of the library, as pointed out by drescherjm in the comments (link about registration of custom classes to the library's fatories if Cmake is not used to compile the project)

Related

Custom libraries in Eclipse with Arduino plugin with cross references

I have an issue with custom libraries that reference headers in other custom libraries.
This is under Eclipse (2020-03) with the 9.11 CDT - Arduino Plugins. (So the latest Version at this time)
Until now I have been using Sloeber, which included all include paths from all custom libraries so everythig was building fine. But with the latest Eclipse/CDT version sloeber does not work anymore. Since it should not really be necessary anymore anyway, I am trying to get my projects to build with just the CDT-Arduino Plugin(s).
Simple projects are Building fine, but more complex have issues…
The build process (makefile generation) seems to scan though the libraries directory, because I can see all the entries in the makefile to build the things it findes in there. But I one of these libraries referneces a header of another one it failes to find it.
Of course I could just edit the include and make it relative, but since these are imported libraries I prefer not to make changes in the code.
With the Arduino plugin there is also no configuration for include paths etc in the project properties any more :-( Normally I would have added the include path there, but the arduino Plugin seems to want to do it all by itself...
Any idea, how I can add the required include paths? Is there a way to do this in the makefile.ini?
I found a different and better way to add custom libraries, which also solves the include path problem. Sadly there is no documentaion about this.
Anyway, it is very simple, just copy the library to the …/.arduinocdt/libraries/ folder. The custom library must contain a library.jason and library.properties file. When opening the Arduino download manager, you can see the new lib and ýou can add it.
Eclipse will read the library version from the json/properties and copy the data in the correct form in a sub directory with the version number.
For libraries added this way, all includes/headers will be found without Problems including libraries referencing other libraries.

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

How do I add the boost library to Xcode 11? C++

I cannot find a way to add boost in Xcode 11.2.1. I found a setting under the target called "Frameworks and Libraries". I dragged the boost directory there, and it got added to the "Frameworks" section of the project. However, in building the project, it says "file not found". For example:
#include <boost/lambda/lambda.hpp>
results in a "file not found" error. Instead of adding boost, I dragged the entire include area of Macports. It took a while for Xcode to parse through that, but I get the same error. So, under Frameworks it has "include", but it cannot find the relevant hpp file, even though I checked and it's there in the boost tree.
I have installed boost via Macports. It resides in /opt/local/include/boost.
In the Xcode documentation, I saw a reference to "USER_HEADER_SEARCH_PATHS". I figured how to set that in a configuration file, so I added a configuration file to the project. I added this to the configuration file:
USER_HEADER_SEARCH_PATHS = /opt/local/include/boost
but that does not work either. (If I remove the boost, that does not work either).
When I select "include" in the Frameworks location of the project, I see that there are different settings "Identity and Type" for that object (right side of Xcode window). I selected "absolute path" and it shows the full path as /opt/local/include which is correct. However, this does not solve the problem either.
Do I need to create a link in a pre-defined area so that Xcode can find it?
I did find a rather ugly work-around: create a soft link to the boost library in the same area where the STL resides (within the Xcode.app directory structure).
Using the setting only works with individual files. I can add individual file to the setting (via drag and drop), but it won't follow nested directories, so clearly this will not work for a library implemention such as boost.
I prefer to keep dependent libraries inside project area. So here is how I just do it for test:
Create new TestBoost project in Xcode from macOS Command-line App C++ template
(now there is TestBoost folder where TestBoost.xcodeproj is located)
Download latest boost boost_1_72_0.tar.gz and unarchive it
(now there boost_1_72_0 folder with boost)
Copy boost_1_72_0 folder inside project TestBoost folder, so it is located aside of TestBoost.xcodeproj
In Xcode Project Navigator select TestBoost project > select TestBoost target > select Build Settings tab
In Search Paths section select Header Search Path, double click on value area and enter ${SRCROOT}/boost_1_72_0 (leave non-recursive flag)
Delete default main.cpp from TestBoost target (to avoid main function confusing) and add some example from boost for testing, eg. boost_1_72_0/libs/algorithm/example/search_example.cpp
Build & Run > Success
Output:

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.

setup include path in eclipse CDT in mac os (headers from framework)

for example I need to include a header
#include <OpenGL/glext.h>
while it is actually a header file glext.h under OpenGL.framework/Headers/.
Therefore it is no way to give eclipse a physical path about "OpenGL/glext.h", and I always get unresolved inclusion warning.
I can still build and run them (with managed makefile project) but it is impossible to browse the functions or definitions from those "resolved" header files.
is there any solution?
While not ideal, my solution to this has been to create a folder "/Developer/Framework Headers" (though the name isn't important), and link from e.g. "/System/Library/Frameworks/Foo.framework/Headers" to "Foo" under said folder. Then in Eclipse I add "/Developer/Framework Headers" to a project's includes.
I say not ideal because apart from having to create links for the frameworks you need and add an include to each project, Eclipse seems to have trouble in certain cases such as nested frameworks (e.g. CoreGraphics beneath ApplicationServices), but YMMV.
Yes there is one. Right click on the project in "Project Explore" window and click on the "property". In there Open "C/C++ General" column and choose "Path and symbols". Now you see all of the include library path for this project. If your using C then add the OpenGL library into GNU C, or if you use C++ then add it into GNU C++. Unfortunately you have to do this for every new project. I have been searching for a while how to do this by default but nothing really useful. Hope this help you get rid of those annoying yellow wave lines.
Since current Eclipse CDT releases don't perform sub-framework header inclusion correctly, you can avoid sub-framework problems (like those generated by the CoreServices header files) by creating symbolic links to the include directories of each sub-framework. I elaborated on this subject, which stems from danhan answer on this question, in this blog post.
In order to automate this process, I've created a Z shell script which automates this process and creates the symlink to the specified frameworks' header directory, together with the links to the include directory of each one of their sub-frameworks. The script can be found in this GitHub repository.
Hope this helps.