XCode can't find OpenSSL headers in /usr/include - xcode

I'm trying to use standard system header files in my C++ XCode project:
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
The build fails and it complains:
"Openssl/bio.h: No such file or directory"
I added /usr/include to the "Header Search Paths" in Project settings, but that doesn't fix it.
I can fix it by adding the whole path like:
#include </usr/include/openssl/bio.h>
-- but the project is full of similar includes and I don't want to change all of them this way. Also, I feel I shouldn't have to do this.
Another way to fix it would be as another thread mentioned, which is to add /usr/include to User Header Search Paths. But if I do that, then I'd have to change all the angle brackets <> to quotes "", which again seems like a hack. I mean, these are standard system header files so I feel it should be something simple, not requiring these kinds of hacks.
Any ideas?
Thanks!

Xcode uses the currently selected SDK as a base path, which it prefixes on to system includes. So if your SDK is /Developer/SDKs/MacOSX10.6.sdk then it will look under /Developer/SDKs/MacOSX10.6.sdk/usr/include by default for system includes.
There are various possible workarounds - I would probably just put a symbolic link in /Developer/SDKs/MacOSX10.6.sdk/usr/include pointing at /usr/include/openssl but you can probably think of others now that you know the underlying problem.

It might depend on the fact that HFS(+) is case insensitive. The error message talks about "Openssl/bio.h" with capital "O", but you're specifying "openssl/bio.h" in the include and the path with /usr/include works.
I suspect that there's some "Openssl" (capital "O") directory in your include path, that gets used when looking for "openssl/bio.h". This wouldn't happen if HFS(+) were case sensitive from the very beginning (I know it's possible to have is case sensitive, but it's actually a PITA to use...)

I've been able to avoid having to specify paths on includes by simply making sure to select Create groups for any added folders for the Folders option in the Add Files to Project dialog which pops up when you're adding the files.
With the other option, Create folder reference for any added folders, I have to manually point it to the file via the full path (and the folder icons show up blue instead of the normal beige). Interestingly, even in this case, AutoComplete sees the file, but Xcode complains it can't find it.

Related

CLion Indexing in Makefile project

So, I understand that CLion currently only fully supports CMake projects. I don't care if I can't compile or run anything with CLion, as I don't currently do that with Eclipse anyway. I am just looking for editor support, with nice click-to-follow, autocomplete, etc.
What I am wondering is whether or not indexing can still work for non-CMake projects. I can create my project just fine, and indexing completes just fine, but after that is done it can't find my include files. It creates a default CMakeLists.txt file, in which the appropriate sources and include_directories have been added. It doesn't seem to make a difference though, as after indexing completes I still can't click-to-follow #include lines, and any references to things in other files don't work correctly.
Is there something else I can do to make indexing work so I can use CLion as an editor, or is this a pipe dream until Makefile support is someday added?
After some research, I found out your best chances are:
Once it's created, edit CMakeLists.txt (for example, see How to
find libraries). One example:
set(Library "../Library")
include_directories(${Library})
set(SOURCES main.cpp)
add_executable(project_name ${SOURCES})
Note ../ goes to the up folder and in the main.cpp you can use #include "header_to_add.h" (header_to_add.h must be in ../Library folder.
Edit the source code of you .cpp, .h or whatever to add the full path of the library you want to #include taking into account the scope starts in the directory where the file is.
For example: #include "../Library/header_to_add.h" (note the "../" goes one level up from the current folder".
(Maybe not possible or hard) Modify the makefile to prepare CMake to get the necessary inputs (for example, see this).
I recommend the first one mainly because it maintains the structure outside the source files.
Edit: Also it's possible to prepare CMake to use makefile (Source).

Including Files - Shared Source And Duplicate Names

I have a situation where I am using two libraries which have duplicate header file names. For example timer.h exists in both libraries. I think the normal solution to this would be to explicitly specify the directory in the include like #include <dir1/timer.h> or #include <dir2/timer.h> so that the compiler has a clue as to which I am specifying. However, my problem is that one of the libraries I am using is not in a sub directory of my project. It exists somewhere else at a higher level. That is...
Root
Library1
Projects
ProjectFolder
Library2
This was done so that multiple projects could reference Library1. It seemed like a good idea at the time. However, now that I have the name conflict of Library2 it creates issues. One other important detail is that I often use two different workstations. The absolute location of Library1 on these workstations is not the same, nor is the relative location (with respect to the project folder) the same between the two. What I have been doing to this point is adding both absolute locations to the search path of the preprocessor.
Anyway, I'd appreciate any guidance you might offer.
You are on the right track with "dir1/timer.h" and "dir2/timer.h". But rather than think of it as dir think of it as "project1/timer.h". Now in your makefile you will need to have the location of project1 added to your include search path if it's not in a common location.
You shouldn't have relative paths in either your code (no ../file.h). They should be relative to the base directory of their project (e.g. #include <sys/socket.h> or #include <linux/sched.h>). Then it's up to your makefile to find them (those two examples are in the standard search path so they will work). For your case you can -I<path to project directory> and then #include "other_project/library.h".
I'd prefer including a copy of a specific version of the external library with my project and updating to a newer version as needed (but not actually changing the external library from the project). If you just refer to the current (changing) version that everybody uses, then your project may change behavior without even having its code changed. A release of your project would also have to refer to whatever version of the library you were using at that point in time to be complete.
If you did it that way, the relative paths are always the same (say, "../ExternalLib") if you want to use that approach. Or you can do as dave suggests.

Xcode header inclusion conflict [duplicate]

I have a project that was compiling ok within g++(I can't see the version right now) and now on xCode it is not.
I think that I got the problem now... I have a String.h file in my project and it seems tha the xCode compiler(that is gcc) is trying to add my own string file from the < cstring >... I am not sure of it, but take a look at this picture
http://www.jode.com.br/Joe/xCode1.png
from what it looks like, it is including my own instead of the system file, I was wondering... shouldn't #include < file > be a system include? because of the < > ? and shouldn't the system include a file within its own path and not the original path of my application?
As I said, I am not sure if this is what happening because I am just migrating to osx these past 2 days...
I was going to change my class and file name to not conflict, so it would work, if this is really the problem, but I was wondering, there should be another way to do this, because now my project isn't that big so I can do this in some time, but what if the project was bigger? it would be dificult to change all includes and class names...
Any help is appreciated
Thanks,
Jonathan
i had the same problem and it was hard to solve. took my hours to fix/find out.
the problem is the headermap of xcode. and the solution - besides avoiding those kind of reserved names, which is a good idea in general, but not always possible with third-party libs - is to add
USE_HEADERMAP = NO
to your user defined settings.
kudos to these guys:
http://meidell.dk/archives/2010/05/08/xcode-header-map-files/
http://www.cocoabuilder.com/archive/xcode/262586-header-file-problem-sorry-to-bug-this-list.html
Naming your headers with the same name as standard headers like string.h and including them simply with #include <String.h> is asking for trouble (the difference in casing makes no difference on some platforms).
As you said, however, it would be difficult to try to figure out what those are in advance when naming your headers. Thus, the easiest way to do this is to set to set your include path one directory level outside of a sub-directory in which your headers reside, ex:
#include <Jonathan/String.h>
Now you don't have to worry about whether the String.h file name conflicts with something in one the libraries you are using unless they happen to also be including <Jonathan/String.h> which is unlikely. All decent third-party libraries do this as well. We don't include <function.hpp> in boost, for instance, but instead include <boost/function.hpp>. Same with GL/GL.h instead of simply GL.h. This practice avoids conflicts for the most part and you don't have to work around problems by renaming String.h to something like Text.h.
Yes, if you use
#include "file"
the local directory is looked first and
#include <file>
only the system include folders are looked.
Notice the word first only in the first case. This means that every time is included your local version should never be reached (unless you have included your source path within the INCLUDE directive).
Said that, my dummy suggestion is to rename your local file with an unambiguous name...
On OSX the filesystem is case insensitive - so String.h you can wind up with conflicts like that. String.h == string.h
it worked by changing the name from String.h to Text.h
but that makes no sense, since the std library is including it's own string.h and not mine.
I mean, makes no sense for a developer to create his files thinking of what names he can't use, for an instance, lets say I change my String.h to Text.h(I already did, I need to work and this is not letting me) ad somehow I had to include another templated library that has a include called Text.h, would I have to change my text.h again or not use this new library? there should be an alternative.
Or shouldn't it?
thanks for the help so far,
Jonathan
Two things you're running into:
As noted above, the filesystem on Mac OS is case-insensitive unless you specifically set up your filesystem to be case-sensitive.
gcc does not distinguish all that much between local and system header include paths. When you specify a directory to be added to the path via -I, that directory will be used to locate both local and system includes. Only when you use -iquote or -I- does a directory get skipped for locating system includes. Further, the builtin "system include" directories on the compiler's search path are always searched for local includes.
Note that the current directory is used for local but not system includes. In this case, I believe it's picking up String.h because the project settings explicitly add the top-level project directory to the include path.
The workaround I would suggest, rather than renaming your includes, is to put your utilities into a directory whose name is unique for your project, and specify that directory in your include directive. For example:
#include "Josk/String.h"
and make sure Josk/ itself isn't in your include search path. This way you aren't stuck with an awkward rename, though you may have to shuffle some files around in your project. You may also need to edit your project settings to make sure the parent directory of that utility directory is in your include path.
Another possibility to try is, if you see the top-level project directory added to your project's include path, remove it. This ought to keep items in your top-level project directory from being searched for system includes.
Finally, you may also be able to avoid this problem in this specific case by changing the case sensitivity of your file system. This can break some Mac applications, though, so research the issue before you embark on this – or pick a volume that nothing else is using.
This question already has some very good answers, yet none of them summarizes in all detail how the compiler will search for header files in general; or more precisely, how Xcode will make the compiler search for them.
When you include a user header, those are header files between quotes ("..."), the following search order applies:
The directory of the file performing the include.
All header search paths in the order provided.
First match inside a header map file, if headers maps are enabled.
Note that the full include path is used. So if your include is in the file foo/bar/file.c and you do a #include "subdir/header.h", then the first lookup will be foo/bar/subdir/header.h.
If that file doesn't exist, the compiler iterates the user header search paths. Those are provided by the build setting User Header Search Path (within config files or on command line it's named USER_HEADER_SEARCH_PATHS). Multiple such path can exist and again, the full include path is attached to each of them until there's a match.
If provides no match either and the build setting Use Header Maps (USE_HEADERMAP) is enabled, Xcode generates a map file of all your header files in the project and searches this map file for an entry that matches the name of the included file. In that case the path is irrelevant, as it would also match just the name of the file.
For system headers, those between spiky braces (<...>), only the search paths from the build setting System Header Search Paths (SYSTEM_HEADER_SEARCH_PATHS) are searched.
However if the build setting Always Search User Paths (ALWAYS_SEARCH_USER_PATHS) is enabled, the user search paths are also searched for system header includes. This allows you to override a system header with your own user header of the same name. Note however, that this is deprecated by Xcode and shouldn't be done anymore.
If your file system is case-insensitive, default on macOS, then case will play no role during all searches.
If you want maximum control over which file is being included, disable header maps and always include with a path relative to the file performing the include (you may use ".." as well). This avoids any ambiguity.

Visual Studio does not honor include directories

I have been in this situation quite a few times where visual studio does not honor the Additional Include Directories when it comes to lib and header source files. For example, I just downloaded MyGUI source code and made sure the include directories were correct. I even put them to absolute paths, Visual Studio still complained that it could not find specific header files.
Does anybody experience the same thing with projects, and if so, is there a solution to this problem?Blockquote
EDIT: My apologies for not being able to explain fully. I know that the library and source files have different include directories. The project that I received had correct directory paths for the Additional Include Directories and Additional Library Directories but Visual Studio still failed to recognize them properly. I can right click and open the header file within Visual Studio but when compiling it still complains it cannot find the required header files. I regularly make projects relying on a framework I myself programmed, so I am quite familiar with how to set up dependencies. This is however the second time this seems to be happening. I don't recall which 3rd party project I was trying to compile last time, but Visual Studio simply refused to believe that the Additional Include Directories paths is where it should look for the header files. I am not sure how to give the complete details of this particular library (MyGUI) but I can point you to the website where you can download it to try and see if it is able to find the header files that are included in the project (if it doesn't compile, that is fine, and it is probably because of additional dependencies, but it should at least be able to find files in the common folder, especially when I put absolute paths in Additional Include Directories)
This happened to me once. It turned out the inconsistency of the Debug vs Release builds. When I modified one build, the other build was being compiled. Please set both builds with same include folders and see if it works. Good luck.
I've just spent some hours battling with failing #include paths in the compiler, inconsistencies between the compiler and intellisense.
What I finally discovered was that in the properties of the *.cpp file -- not the project, but the individual *.cpp file -- the "Additional Include Directories" property was blank. I had to explicitly set it to "inherit from from parent or project defaults" -- there's a checkbox near the lower-left corner of the dialog for editing the directory path.
I had copied this file from another project and used "Add > Existing Item..." to add it to the current project. My hypothesis was that maybe the "Existing Item" procedure skipped a property initialization step that "New Item" would normally perform. But I just tested that hypothesis by Adding another Existing and a New. Both of these files had their property set to inherit from the project, so I don't have an explanation for why my problem file was not initially set to inherit.
Anyway ... after much frustration, found and fixed that one.
I have found (stumbled) on the solution (I think). It has something to do with the character limit imposed by the OS. Although the limit should be 260, for me it falls in the below 150, see this discussion and links to it. I downloaded and unzipped the file to C:\Users\MyUserName\My Documents\Downloads\Downloads From Chrome\MyGui3.0...[and so on]. I learned quite some time ago not to try to compile projects under such long paths, but this time it completely slipped my mind as VS did not give me a warning at all and pointed me in the wrong direction. Anyway, cutting and pasting the project to D:\ fixed the issue. I am not going to checkmark the answer however until someone confirms this.
I have the same problem : Can't find .lib file even though I've added the additional include directory.
From an answer of Additional include directory in Visual studio 2015 doesn't work, I tried:
delete the .suo file and restart VS
Then it works for me.
I had this issue too. Just like sam said - this string value containing path to your framework includes has to be the same for the Debug and Release configurations. So the best way is to choose "Configuration:All Configurations" and "Platform:All Platforms" from the two context checklists on the top of the project properties window before typing it in, or copying from windows explorer adress bar.
Can you elaborate on this? If I recall, there are at least two places in Visual Studio where you can configure this:
Per-installation: Tools/Options/Projects and Solutions/VC++ Directories)
Per-project: Project/Properties/Configuration Properties/"C/C++"/General/Additional Include Directories
If you're adding the include directories per-project (#1), which I think you are, and then trying to include from another project, this will obviously not work. Try adding them at the per-installation level and see if it works.
Also, this may sound stupid/simplistic, but make sure the path is right (i.e. copy-paste into Explorer's path bar and see if the header files are in that folder).
If by lib files you mean library (.lib) files, the directory location is not specified through C/C++/General/Additional Include Directories but rather through Linker/General/Additional Library Directories.
It's logical if you think about it. C/C++ options are all compilation options, settings involved with compiling .cpp and .h files. Linker options are all linking options, settings involved with linking up .obj and .lib files.
I had the same symptoms in my c++ project. Navigating from header to header went fine, but after toggling to the source file of a header (let's say foo.cpp), then the navigation to an #include <bar.cpp> in that source file failed. I got the following error:
File 'bar.cpp' not found in the current source file's directory or in build system paths.
After research I noticed that the system build path given in the error where not extended with the include paths of the project. In other words: IntelliSense didn't know that the source file (foo.cpp) was part of the project, and therefore it didn't use the include paths of the project to search for the #include <bar.cpp>.
The fix for me was creating a file intelliSense.cpp (file name doesn't matter) that is part of the project, but excluded from the build. This file contains an include for each source file. ex:
#include <foo.cpp>
#include <bar.cpp>
...
This way IntelliSense knows that these source files are part of the project, and will therefore use the include paths of the project to resolve the #includes in those source files.
For me the issue was that .vcxproj Project file was read-only and after I added my directory to "Additional directories", the project file did not actually change. I was surprised that VS did not complain about this file being read-only.
So after I made that file write-able I could compile my project.
Here is another 'I had the same...' in vs2015.
For me it turned out that the active setting is also depending on the 'solution configuration' and 'solution platform'. That makes 4 settings which all should be identical.
That solved the problem in my case.
I realize this question is over 10 years old at this point, but I also just ran into this issue and none of the answers fit my scenario. After some playing with my IDE (VS 2019) for a few minutes I realized that the cpp file I was using had it's platform set to Win32, but the libs I was trying to use were built for x64.
As others have stated, make sure your project's configuration is set to
-"All Configurations" when you add the necessary paths to your project as that can also be an issue. I imagine my issue will not be as common, but I figured it was worth sharing. I hope this helps someone else in the future.
One more possible reason not mentioned earlier: make sure you are configuring properties of the correct project in a multi-project solution.
My problem was that I had a solution of two projects each using the same file with includes. Turns out that I correctly configured 'Additional Include Directories' only for one of two projects and totally forgot about another one. Of course error message was stating that only the second project and not the first one had problems.

Boost 1_44 includes don't work

Sorry for what seems like a silly question: But I've never, ever worked with boost, until tonight, and I'm finding that getting it configured seems to be harder to use than it should be.
I wanted experiment with it tonight. So I downloaded the zip file, and unzipped it to a directory here:
F:/boost_1_44_0
Then I created an empty c++ project in visual studio 2010 (not using pch either). So all I wanted to do was to include a header file. But not even a silly thing like that seems to work. Now I've been using visual studio for years, though at work we are still stuck on vs 2008 (That is another story). So usually what you do is set an include directory, and then you can include files in at will right?
So I set the global include directory to include the boost root. i.e. Property Manager -> My configuration (debug|win32) -> Microsoft.Cpp.Win32.user -> Common Properties -> C++ Directories -> Include Directories. There I added my path to f:/boost_1_44_0.
I also went to the project properties and set the C++ include directory for the project to point to the boost root like in vs 2008.
I then added a silly include declaration like so:
#include <boost/lambda/lambda.hpp>
But, amazingly it fails to compile!!! with the following error:
Error 1 error C1083: Cannot open include file: 'boost/type_traits/transform_traits.hpp': No such file or directory f:\boost_1_44_0\boost\lambda\core.hpp 25 1 test_boost
Which when I double click it, it opens up in f:\boost_1_44_0\boost\lambda\core.hpp, and takes me to this line:
#include "boost/type_traits/transform_traits.hpp"
So I have no idea what's happening. Is visual studio just not delivering up my global include paths that I set? It seems also that the include directive in core.hpp should be using angle brackets and not quotes.
If I'm doing something wrong what?
EDIT:
!! SOLVED !!
Before I didn't have all the files unzipped. I don't know what happened. So I re-downloaded the zip file, and unzipped it again. This time the zip file took much longer to unzip, and it extracted much more files: Including the missing files.
Problem solved, my hello world app compiles just fine now.
The behaviour of compilers in locating header files is implementation defined for both the <> and "" variants.
However, based on this page for VC2010, it appears the quoted form searches a superset of the angle bracket form so I'm not sure that's the problem.
I suppose it would be a silly question to ask if the following file actually existed?
f:\boost_1_44_0\boost\type_traits\transform_traits.hpp
So, a couple of investigative jobs:
Make sure that f:\boost_1_44_0\boost\type_traits\transform_traits.hpp exists.
Try changing your top-level include to use quotes.
Try changing the include in f:\boost_1_44_0\boost\lambda\core.hpp to use angle brackets.
Make sure you try all four possibilities for those last two.
Is f: a network-mounted drive? What happens if you put it all on c:?
That last one is just in case Windows is doing some shenanigans under the covers :-)
While it's a bit overkill for this, learning to use SysInternals' Process Monitor will pay off over time. It will show you what files are actually opened, and which attempts failed. Look where Visual Studio tries to read transform_traits.hpp from, and you'll probably have the answer.

Resources