Select common files in 3 different directories - fortran

I have 3 different directories, let's say:
path1/directory1/
path2/directory2/
path3/directory3/
(the paths to the directories are not the same!)
and each directories has several files (like 200 files).
What I want to do is select the files common to all three directories (that is the intersection of directory1,directory2 and directory3).
I am using Fortran 90 with the GNU compiler.

Related

C++ cannot open source file "opencv2/tracking.hpp"

I am trying to use OpenCV multi-tracker, but it doesn't find tracking.hpp. I have built OpenCV with OpenCV-contrib modules based on these instructions. Now in Visual Studio, I have done this:
where $OPENCV_DIR is a user variable:
I also have;
added the path C:\opencv\opencv4.2.0\opencv-4.2.0\build\install\x64\vc16\lib to the Linker -> Gnereal -> Additional Library Directories.
added opencv_world420.lib to Linker -> Input -> Additional Dependencies
Now the problem is that opencv.hpp and tracking.hpp aren't detected:
Both opencv.hpp and tracking.hpp exist in C:\opencv\opencv4.2.0\opencv-4.2.0\build\install\include\opencv2. What should I do to make the program recognize OpenCV-contrib modules?
Note: This answer has been formed largely by combining and expanding on comments made by myself and others:
The problem is a 'conflict' between your specified "Additional Include Directories" and the specified name of the header(s) in your #include lines, in that you have specified the folder, "opencv2" twice.
For example, the line:
#include <opencv2/tracking.hpp>
Looks for the file tracking.hpp in a sub-directory called opencv2 in each of the defined search paths. In your case, this is looking for:
OPENCV_DIR\include\opencv2\opencv2\tracking.hpp
… and that file (in fact, the folder) doesn't exist.
So, just specify this as your (single) "Additional Include Directory:"
OPENCV_DIR\include
… then, when the compiler 'constructs' the path for the header, it will append /opencv2/tracking.hpp to (each of) the specified search directories, and will be able to find: OPENCV_DIR\include + / + opencv2/tracking.hpp, as this will evaluate to:
OPENCV_DIR\include\opencv2\tracking.hpp

Visual Studio C++ include all file in all subfolders of directory

In a C++ project in Visual Studio in:
Project Properties > Linker > Input > Addtional Dependencies
I could write $(MyEnvVar)\folderA\*.lib to include all libraries.
But let's say folderB has many subdirectories which each has a set of header files.
If I want to include them all in one go, in:
Project Properties > C/C++ > General > Addtional Include Directories
I would like to write something like: $(MyEnvVar)\folderB\*\ or $(MyEnvVar)\folderB\*\*\ to go one subdirectory deeper in each folder.
This doesn't seem to work.
Optionally I could do $(MyEnvVar)\folderB\ and in my code I would include each file as #include "name_of_subfolder\name_of_file.h". (This is what I want to avoid.)
Is it possible in one line to include all files in all subfolders of a certain folder?

How to enforce additional include files search order in VC++ project?

For example I have two header.h files located in two different directories include1 and include2.
My source code file uses regular inclusion that doesn't specifies the exact location, like this:
#include "header.h"
In the project configuration I set my both include1 and include2 folders to be in the additional include directories list.
The problem is when I build my project, include1 folder will be chosen every time, regardless of the order I defined them in the additional include list.
Is there any way to enforce a search order, if I want a specific folder, or specific header file to be used, instead of another, if they both have the same filename?
The include order (as documented by MS) is:
The compiler searches for directories in the following order:
1. Directories containing the source file.
2. Directories specified with the /I option, in the order that CL encounters them.
3. Directories specified in the INCLUDE environment variable.
So it really depends on where the include directories are declared. If they're both specified with the /I option (in the GUI under Configuration Properties > C/C++ > General > Additional Include Directories), then the order specified is the order searched. If the directories are in the INCLUDE environment variable (in the GUI under Configuration Properties > VC++ Directories), it depends where they're declared. If it's in the property sheets then you'd have to not inherit them and declare them (and other inherited directories) yourself in the desired order.
I think your problem is going to be difficult to solve. I suspect that header.h is included from a file in folder include1.
That means that the standard C include path is
Directory of the source file (or header file which is including a sub file).
Order defined by the command line include.
So to fix this, we would need to be able to stop (somehow) the rule 1 from firing.
The use of #include "projecta/header.h" and #include "projectb/header.h" are normal methods to achieve this, if you are not concerned with modifying the source.
In your case, you want to ensure your (include2 is included.)
Methods you could apply.
If earlier code (.c/.cpp files) is modifiable, then ensure you #include "include2/header.h" - which should also set up so all requirements forinclude1/header.h` are satisfied.
if include1/header.h has an include guard (#if ! defined( H_HEADER_H) ) then define this at the command line (/DH_HEADER_H), so it is not included - this is a stab in the dark, as the file will not fulfill its purpose.
Write a text modification script (sed?) to modify "header.h" to be "include2/header.h" - which ensures all occurrences in the source choose your version. That is not too you specification, but could be conceived as leaving the source unchanged, as it would be a pre-compile step.
The goal for guaranteeing the change of order of include may be achieved by creating 2 separate projects - one which uses include1/header.h and the original code unchanged. Then offers out include2/header.h as its interface that is modified in some way.

CMake: ordering of include directories (How to mix system- and user-based include paths?)

I've got a CMake project that includes and links against two libraries, say A and B (actually it's more than two and one of them is boost stuff, but that doesn't really matter here). Both are located via FindSomething.cmake scripts that (correctly) populate the standard CMake variables such that include directories are added via
INCLUDE_DIRECTORIES(${A_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${B_INCLUDE_DIRS})
and linking is later done via
TARGET_LINK_LIBRARIES(mytarget ${A_LIBRARIES} ${B_LIBRARIES})
Now, the problem is that both libraries can either reside in a user based location or in the system directories (I'm on linux by the way, CMake 2.8.2) - or in both. Let's say A is only in $HOME/usr/include and $HOME/usr/lib while B (boost in my case) resides in both the system paths (/usr/include and /usr/lib) AND in the user based paths - in different versions. The find scripts can be made to find either the system or the user-based library B, this works.
The trouble starts when I want to link against B from the system paths.${B_INCLUDE_DIRS} and ${B_LIBRARIES} correctly point to the system-wide locations of the headers and libraries. But there is still ${A_INCLUDE_DIRS} that points to a non-system include directory and ultimately also the headers for library B are taken from this location, while the linking for B uses the version from the system paths (via ${B_LIBRARIES}) which leads to conflicts, i.e. linking errors.
Changing the order of the INCLUDE_DIRECTORIES statements does not seem to change anything. I checked the origin of the symbols that cause the linking errors via nm --line-numbers on the object files.
What can I do? Is there a trick to
force the ordering of the include directories (even if this would mean to give precedence to a system path although there is also a user-based location specified)?
tell CMake to use ${A_INCLUDE_DIRS} for all headers from A and ${B_INCLUDE_DIRS} for all headers from B?
Here's what CMake says about include_directories():
include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])
You can specify that you want to have include directories searched before or after the system include directories at the time that you tell it about those directories.
You may also be specific to a target:
target_include_directories(target [SYSTEM] [BEFORE] [items1...] [ [items2...] ...])
If A and B are different libraries containing different header files and paths, there should be no problem doing what you are doing right now.
That being said, if A and B are similar libraries containing header files of the same name at the same location, that is problematic. In that case, the order of the include_directory() call is important. I ran a little test where I had three copies of a header file. The first copy is located in my system path (say /usr/include). The other copies are located in two user-defined locations (say /tmp/include1 and /tmp/include2). The file in /tmp/include1 is found and used first if I put the include_directory() call in the following order:
include_directory("/tmp/include1")
include_directory("/tmp/include2")
The file in /tmp/include2 is found and used first if I put the include_directory() call in the following order:
include_directory("/tmp/include2")
include_directory("/tmp/include1")
If I put no include_directory() statement, then the header in the system path is found and used.
You may want to re-check how your FindSomething.cmake are written. The search order of the find_*() CMake commands can be found in the CMake documentation,
As far as I can remember, there is now way of telling CMake to use ${A_INCLUDE_DIRS} for all headers from A and ${B_INCLUDE_DIRS} for all headers from B if the header file can be found in both location. It all depends in what order the include_directory() call are made. If the FindSomething.cmake are written properly, if the CMAKE_MODULE_PATH (this is the location where CMake will look for the Find*.cmake files) is set properly and all the paths are good, then you should be good to go. If not, I will need more information on your current CMake/library setup.
When using third party libraries, I would always do this
Library A + B header files:
third_party/include/libA_name/ <-- put header files in there
third_party/include/libB_name/ <-- put header files in there
In source files you would always use it like this
#include "libA_name/file.h" <-- no ambiguity possible
#include "libB_name/file.h" <-- no ambiguity possible
Then you can still use -I "third_party/include" as the include folder and no ambiguity in ordering will happen in source files.
This also disambiguates custom header files from system header files which could clash from time to time from 3rd party libs.
For me this worked fine:
INCLUDE_DIRECTORIES(BEFORE ${A_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${B_INCLUDE_DIRS})

How to include header files in Visual Studio 2008?

I am currently trying to compile a simple program that includes two header files. I see them in the Solution Explorer, where I included them through "include existing files". However, when I run my program it get the following error.
fatal error C1083: Cannot open include file: 'FileWrite.h': No such file or directory. THe problem is that I see the file included in the Header's folder and in the code I have written:
#include "FileWrite.h"
and then the rest of the program code.
Is there something else needed to do so that the compiler can see the header file and link it to the .cpp file I'm trying to compile?
If you write in your code something like #include "FileWrite.h" you need to make sure compiler can find that file. There are three options:
FileWrite.h should either be in the same directory as your source code file (.cpp) or
Path to that header file should should be listed in project's Properties (in C/C++ -> General -> Additional Include Directories) or
Path could be set in your VisualStudio - add it to Include Files in Tools->Options->Projects and Solutions->VC++ Directories
Which of these options shell be used depends on whether that header originates from this project (1st option) or some other project (any of other two options).
There are two ways to do this.
1) Only for the current project
Select your project -> properties -> C/C++ -> General -> Additional Include Directories -
Include your header file directory.
2) For all projects
Tools -> Options -> VC++ Directories -> Include files - Add the header file directory.
Refrain from using 2, as it would be difficult to figure out dependencies for a project when compiling it on a system different than yours.
When including files the compiler first looks in the current directory (the directory which contains the source .cpp file) then it looks in the additional include directories. If FileWrite.h isn't in the same directory as your source file check the additional included directories.
In the project's property page look at the additional include directories and see if they include the folder in which FileWrite.h is in.
You said the file is in the "headers" folder. This could either mean the headers filter or an actual headers directory on the filesystem. When including a file from your own project you need to specify the path from the file you're including into. So, if you had something like so:
src/main.cpp
include/my_object.h
You would use #include "../include/my_object.h" in main.cpp.
That's for directories. The folders you see in your project are called filters and have absolutely no relation to the directory structure of your project unless you force it to. You need to be paying attention to what the structure looks like in windows explorer to ascertain what path to use in an include statement.