Earlier I asked for help in including an external library called Eigen in xcode 4. I finally managed to get it to include the header file I wanted to use, Array, by going to build phases, link binary with libraries, and then adding the sub-folder within the Eigen archive where Array.h was located, Core. I also added the filepath to Core's parent directory, src, in header search paths.
When I finally managed to add the line of code #include <Core/Array.h> without it getting highlighted as an error, I ran the application (which worked previously) and XCode said that the build failed, with the error messages citing semantic issues. I checked the error message and they include, "Uknown identifier 'Array'" in a file named Array.h.
All of the header files are in src and according to the Eigen website, they are all that's needed to use Eigen with c++. I've attempted to reformat the binary links so they go to src instead of Core, and adjusting the buildpath to lead to the parent directory of src, ensuring that all header files can now be accessed, but I'm still getting semantics issues. Does anyone have a solution to this?
You generally want to include the Core file, not the individual .h files, i.e.
#include <Eigen/Core>
There are exceptions, but again, you won't be including the .h files, those are used internally. Additionally, it appears that your include path points to the ./Eigen/src/ directory. You want to move it up two directories so that when you write #include <Eigen/Core> it finds the Core file correctly. The files that you'll most likely include are the extension-less ones in the Eigen directory.
Related
I am trying to include Glad (generated from here with the GL3.3 api (having similar include problem with GLFW as well)) as such
#include <glad/glad.h>
I feel like this should work since I have my additional include directories for the file in the project as
vendor\Glad\include
where my VS solution has the file structure of
-solutionName
--projectName
---src
----projectname.h <- Where I am including from for now, latter I want to include from elsewhere under the src directory.
---vendor (same level as src)
----Glad
-----include
------glad
-------glad.h
------KHR
-------khrplatform.h
I have been able to get the include to work by including the file as
#include <../vendor/Glad/include/glad/glad.h>
but when I do this I get an error ("C1083" "Cannot open include file: 'KHR/khrplatform.h':No such file or directory") because an include in glad.h can't find khrplatform.h when it includes like so
#include <KHR/khrplatform.h>
I could change that line in glad.h but I really don't want to have to change a library's code to make mine work.
This also happens with GLFW which has mirroring additional include directories and file paths but with glad replaced with GLFW where applicable.
In addition Visual studio will offer the
<glad/glad.h>
file path as a suggestion when I am typing out the include line in projectName.h but I still get the error "C1083" "Cannot open include file: 'glad/glad.h': No such file or directory".
Another quirk is that I am using spdlog file the additional include directory
vendor\spdlog\include
and am able to include headers in the src directory as such:
#include <spdlog/spdlog.h>
which works and doesn't throw and problems.
The file structure for this is
-solutionName
--projectName
---src
----Utilities
-----Logger.h <- Where I am including from.
---vendor (same level as src)
----spdlog
-----include
------spdlog
-------spdlog.h <- file I am including just fine.
This makes it feel like only some of the additional include directories are actually working and I'm not sure why is this happening or how can I fix it after spending a couple hours playing guess and check. I want to include the libraries like
#include <glad/glad.h>
#include <GLFW/glfw3.h>
How can I make this work?
Thanks for your time,
-Michael
Use "glad/glad.h" instead of <glad/glad.h>.
With the angle brackets the compiler searches only the standard paths for includes, with the quotation marks it also searches the additional include paths that you defined.
Alright so I figured it out finally, I'm not happy with how I had to do it but I guess it works so I'll move on unless anyone has suggestions. So, the problem came down to that I was including the headers in a static lib I was making then used that static lib elsewhere. (I hadn't realized this was a problem otherwise I would have mentioned that in my original question, sorry everyone.) I included my lib by a header that includes all the dependencies that I want to have access to and later down the line these 3rd party static libs will git more and more abstracted but for the time being what I had to do was also tell my other "sandbox" (non library) project to also have additional include directories like
$(SolutionDir)MyLibName\vendor\Glad\include
and
$(SolutionDir)MyLibName\vendor\GLFW\include
Ideally I didn't want to include anything except MyLib but I guess this is my work around for now. Thank you to everyone who offered suggestions!
I decided to make a header file(s) that includes all the relatively simple methods I frequently use,to simply include said file into any project I'm working on instead of having to copy methods from one project to the other every-time I need them,I'm also going to be updating this file(s) as I go,now,I know there are multiple ways to go about including said file,either by adding it's file path to the #include directive itself,something like:
#include"C:\\Projects\\MyProgram\\Files\\MyHeader.h"
Or by adding the folder containing the header file(s) to the Additional Include Directories in the project's properties,which is what I'm currently doing,and it's working just fine.
However,I'm a bit worried about the fact the header file is not included INSIDE the project folder,so in the event I had to switch computers or wipe my hard drive,I'd have to make sure that this header file(s) is placed in the same exact file path,otherwise all of the projects that include it will simply fall apart...
And it goes without saying,I'm not making a copy of the header file to place in each project folder,for obvious reasons.
So I'd like to know if there anyway around this?
How about the ability to set an Additional Include Directory for ALL of my projects,so in the event of a wipe,a new PC or simply the old directory becoming inconvenient,all I have to do is set a new directory and all of my projects will start referring to that one?
If not,is my only choice is to build the header file(s) into a custom library? Because I know absolutely nothing about that,and I'd appreciate if someone would direct me to where I can learn to do that.
Thanks in advance.
You must use relative path. Do this:
1- Create a new subfolder in your solution. Let's call it include:
2- Put your shared headers in this subfolder. Example : myCommonFunctions.h
First solution: Use relative include path (see ../ at begining)
#include "../include/myCommonFunctions.h"
Second solution: Use relative path in Addtional include directories (see ../ at begining)
Now, you can write :
#include "myCommonFunctions.h"
By doing this, you don't depend from an absolute path C:\\Projects\\MyProgram\\... and You will no longer need to copy files manually if you change computers
I'm trying to make a cross-platforms crypto library in C++ at https://github.com/haithngn/cryptor something like https://github.com/MailCore/mailcore2
The Structure is:
Can I make any header files can be include in the statements like this:
#include <Cryptor/MD5Encryptor.h>
I can include these header directly from absolutely file path
../core/CryptorCore.h
But these format will make the source code cannot build succeed in an XCode Project.
I tried to simulate the MailCore2 but that's very difficult.
Hope you can suggest me any solution or do a favor PR on my Repository.
Thanks,
You need to have a proper hierarchy. First, no, you can't have
#include <Cryptor/MD5Encryptor.h>
with your current setup, not while building the library, and not without flattening the hierarchy when installing your files (which CMake can do).
What you can do is:
#include <Cryptor/core/abstract/MD5Encryptor.h>
if you add your project inside a Cryptor folder instead of being at the root of your project.
I would advise you to create a Cryptor.cmake file that would allow people to pick up your library once installed, so that they don't have to know where the library includes are or what the libraries name is.
It should not be necessary to point to every single header file. Just add all directories containing these header files with include_directories(PATH_TO_HEADERS).
For the include of the header file src/core/CryptorCore.h with
#include "CryptorCore.h"
you have to point to
include_directories(${PROJECT_DIR}/core/)
Eigen is located in the file
C:\Users\jherb_000\Downloads\eigen-eigen-07105f7124f9
I thought to include eigen you just use
`#include "C:\Users\jherb_000\Downloads\eigen-eigen-07105f7124f9\Eigen/Dense" `
But it is not compiling. I know it can work because I have done it before, and the eigen website does not explain how to do this unless you are using specific programs like g++.
Since you imply via the tags that you're using qt-creator, your problem boils down to "How do I add an include directory in qt-creator?" There are answers for that here, here and others. One thing to note is that the path you should add is C:\Users\jherb_000\Downloads\eigen-eigen-07105f7124f9.
What happens is when you include a specific file in a specific directory, if that file doesn't #include any other files (ok, other files that aren't in the include paths) all works well. But if it does, (and Eigen files include other file in the Eigen project) then the compiler does not know where to search for them. That's why you have to explicitly tell the compiler which directories to look for files that are included.
Very easy. Let's say you have a dependencies directory, and inside you have the eigen directory. In your .pro file, you could add your dependencies path to your INCLUDEPATH:
INCLUDEPATH += ../dependencies/ # or wherever that path is (relative to your .pro file)
Then, to include the Dense module, you do:
#include <eigen/Dense>
where eigen refers to your folder eigen in your dependencies folder. Many variations possible in function of your setup, but you got the idea.
Ok then what you need to do is:
Copy the C:\Users\jherb_000\Downloads\eigen-eigen-07105f7124f9\Eigen directory and all it's contents to wherever you're keeping all your third-party library files on your machine. (You probably wouldn't want to keep these files in your Downloads folder). For example let's say this directory is copied to C:\jacks_code\Eigen. Then,
Add this new directory to Qt-creator's list of directories to search (see Aki's answer for links):
In each of your source files, to include the Eigen templates, use the preprocessor directive:
#include <Dense>
The compiler will use the directories you told it, to dereference the file to C:\jacks_code\Eigen\Dense (the complete filename). It's a bit confusing here because the files in the root Eigen folder don't have .h or .c or .cpp or .hpp extensions.
Hope that helps. You can also read the INSTALL file in the base of the unzipped package.
I am trying to compile a program that uses rocksdb.
According to the example in the official webpage, the only header i should add to my code is db.h.
Now, the file i am compiling is in folder A.
db.h however is in A/rocksdb-master/include/rocksdb/.
So, i add this line to my file:
#include "rocksdb-master/include/rocksdb"
It finds the file, but the problem is that inside db.h, i have this line:
#include "rocksdb/metadata.h"
And when i compile i get this error:
fatal error: rocksdb/metadata.h: No such file or directory
#include "rocksdb/metadata.h"
I mean, it's obvious. db.h is in the same folder as metadata.h, so it's fine that the compiler cant find any rocksdb folder. But i doubt that people who wrote this library don't know that.
Is there any other way to add the path's to compile it?
Why is it that the path from db.h are not relative to where it is located?
You should normally use just the following header in your project:
#include "rocksdb/db.h"
When compiling your own project, you should then add the RocksDB include path to the list of include directories. For example, if the RocksDB source code is in directory ../rocksdb-master, the include path will be ../rocksdb-master/include.
How to add the include path to the compiler flags is indeed compiler-specific. With g++ or clang, it's done by passing -I../rocksdb-master/include to the compiler when compiling your own program. Note that you many need to link against the RocksDB library as well.
And finally, you may need to include some more RocksDB headers if you use some of its advanced concepts, e.g. transactions.