XCode does not add c++ source files that are in subdirectories into Compile Sources - c++

I use XCode 5.1 for C++ development. I have existing code which I add to the project by dragging files from Finder. The project shows all necessary .h and .cpp files. But when I click Build Phases->Compile Sources, I only see sources that from the root directory in my source structure. None of the source files from subdirectories appear in the Compile Sources. Why? And how to fix this?
Also, when I try to add the missing .cpp file from Build Phases->Compile Sources by pressing +, XCode does not expand the subdirectories, so I cannot select the missing .cpp files.

This is unbelievable. The only problem was that I was adding folder structure with Create folder references for any added folders option instead of Create groups for any added folders.
But still don't understand what is the difference in terms of recognition of source files.
Other peculiarity is that you should add resource files in opposite way (Create folder references for any added folders). Otherwise the iOS application does not find the files and does not compile.

Related

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

How do I get Code::Blocks to display .h and .cpp files in the same directory?

I am very slowly figuring out Code::Blocks and am trying to set it to my liking.
The gentleman that provided the second answer in this post: Organization of files in Code Blocks seems to be able to get C::B to display his header and source files in a single directory in the project tree. This is what his project tree looks like (and how I want mine to look):
However, in my case, anytime I create a header file, C::B displays it in a new directory called 'Headers' (see image below). I should mention that I am keeping the .cpp and .h files together in the same directory when I am creating the files.
I looked all over environment settings, project properties, C::B documentation, online, tried to ask the poster of the link (but i don't have enough reputation to put comments) and I am stuck. Very stuck.
If you know where the setting in C::B which needs to be changed to display the two file types together (like in the link above), I would really appreciate your help.
The Sources and Headers folders that by default appear to contain
respectively the source and header files of a C::B project are virtual
folders that represent the "categories" (header, source) of the files
within.
To disable this virtual organisation of your project:-
Right-click on your project icon in the project workspace
From the pop-menu select Project tree
In the Project tree sub-menu uncheck the item Categorize by file types

Include c++ files outside project directory in Eclipse

I have a problem regarding including files that are outside project directory (c). So I have a project in a workspace. There is a folder somewhere on my hard drive, containing a pair of .h and .c files. I would like to use them in several projects, that's why I wanted to place it outside the project.
I tried including this folder, .h file actually in many ways, but the compiler doesn't seem to see the content of it. I can successfully include the file, but the functions inside are not visible.
In the properties of the project -> C/C++ General -> Paths and symbols I have added the folder. What else should I do?
Add the relative path of all those *.c and *.h file.
#include "path_to_header/lib1.h"
#include "path_to_file/file1.c"
I was wondering about the same recently, here is what worked for me:
You have to mark the files as source code. Open project properties dialog and go to source location tab
then you can use Link Folder to select absolute path or you can use the variables to keep it relative to project file or workspace.
For other configurations Add folder was enough since they were already linked.
You also need to add include paths to c or c++ here
There probably already are some default paths so just add the new ones.
It can also be relative using variables.
I had more sub folders so I added them individually and did not use and relative path in #include at all.

Subfolders in xcode. Linking

I added a subfolder to my project(blue folder in xcode) and specify to search headers in all subfolders. Now headers are found, but after compilation project can't link. I suppose this is because my subfolder isn't compiling. But when i added subfolder in compile source in Build Phase pane nothing has changed. Strange thing that i can't add only one file from this subfolder to compile source.
It looks like you added the folder as a Folder Reference in Xcode, rather than adding the actual source files to the target.
When adding the existing source files and folder, ensure to expand the "Options" area in the file browser and select the "Create Groups" option for added folders.
Also ensure "Add to targets" has the correct target selected.
Solution: Use cmake tool for build xcode project from source.

Netbeans ignoring files

In Netbeans when I create a new C++ project from existing sources only the Makefile appears to be under Git version control. The other files (.h, .cpp) all appear to be ignored (grayed out) when viewing from the Projects or Files windows in Netbeans.
How do I make these files tracked?
I have already tried the right-click unignore option.
I do not have a .gitignore file at this point.
You can ignore files in git in other ways than using the .gitignore.
In project folder check the file .git/info/exclude - you can exclude files which yu don't want to keep in .gitignore (which is usually shared with other coders)
You can also ignore files on a global level. Check the settings of Netbeans - it might have a global ignore list used by git.