I have a header file named A.h, another header file named B.h.
In B.h,
#include "XYZ/A.h"
but Xcode complains "XYZ/A.h" file not found.
I tried to make a subfolder XYZ in the folder where B.h is, and put A.h into XYZ, but the same error.
How to solve this? ===> Set parent folder of XYZ folder in project build setting "header search path". Problem resolved!
I don't want to change the header file B.h - I want to keep the relative path "XYZ/A.h".
PLEASE NOTE:
Both A.h and B.h are added into project (dragging...), and their physical location is not same with group folder in Xcode project. They may be in different folders in disk.
I am not particularly familiar with XCode but generally the compiler needs to know where to start looking when using relative include paths. For this reason, through compiler options or project options (since you are using an IDE), you must set the path to the directory that contains the directory XYZ. So if the path to XYZ is '/home/user/XYZ', then you need to add '/home/user/' to the search paths.
Now this is generally speaking. XCode may do it in a slightly other way but the point should be the same.
Related
After adding the include directory of the library which I am using. Visual Studio 2010 is able to find the header files I #included into my source code (IntelliSense does not show any errors). However when building the solution, it tells me that it wasn't able to find the header file. The same property used in my previous project does not post this issue.
The only solution I have now is to use the direct address for all the header files from that library, but I find it very irritating to do so, as the header files of the library cross reference each other and it does not make sense to edit all of them.
Does anyone have any idea what causing this problem?
It might because you have source + headers in 2 directories that refer to each other's header files. I.e. the files are
1/a.c
1/a.h
2/b.c
2/b.h
and the contents of a.c and b.c have the same includes
#include "a.h"
#include "b.h"
Your project can find a.h when compiling a.c, and it can find b.h when compiling b.c (since the same directory is assumed in the search path when you use double-quotes in #include "xxx"). But a.c can't find b.h and b.c can't find a.h by default. Your project might be in directory 1 and you may have set up the include directory to look at 2. That works fine until 2/b.c needs to include "a.h". You need to set up the include directory path to include 1 as well as 2, even though 1 is your original project directory and it seems silly to do that.
This is a reason why IntelliSense can open the files (since it is omniscient), but the compiler can't (since it just looks at one file at a time).
IntelliSense uses a slightly different algorithm when searching for include files compared to the compiler & linker. In particular, it can also (sometimes) find header files even though the include directories are not properly specified.
I'll assume you specified the include directories correctly.
An idea: There's a bug in Visual Studio 2010 that if you specify a rooted path (ex. \myproject\includes), then when building the solution, VS uses the drive where it is installed (usually C:) rather than the drive where the solution is located. If this is the case, you'll have to either specify the drive (ex. D:\myproject\includes) or use a relative path (ex. ..\..\myproject\includes).
It seem like the actual problem is cause by me not adding the include directory in the project which was referring to the project which was implementing the library.
This explain why I could build the referred project by itself and only having the problem when I compiled the solution as a whole.
I find this rather dumb to require us to re-declare the include directories in referring project when we have already done so in the referred project
In netbeans I am creating a new folder and adding header files to it.
Now when I include the header file within the newly created folder to another file by using:
#include "folder1/myheaderFile.h"
The compiler complains that it is unable to find the header file.
The error is:
main.cpp:31:39: fatal error: folder1/myheaderFile.h: No such file or directory
Is there some way out as I want to include the header files within a folder in my #include?
EDIT: Do i need to make a makefile for every folder?
Another EDIT:
When I right clicked on the error its showing
unresolved directive
#include
Analyzed system include paths:
/usr/include/C++/4.6
/usr/include/C++/4.6/x84_64_linux_gnu
/usr/include/C++/4.6/backward
/usr/lib/gnu/x86_64-linux-gnu/4.6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu
/usr/include
Here's for your convenience:
The include file paths you have specified are for system-wide headers. Is the header you are including yours or downloaded/installed system-wide? Do you see the path of the header in the output?
If you are including the header which is in a folder, from another folder, then you need to traverse back, i.e: #include "../folder/header.h"
If this is a system folder, such as the ones residing in /usr/local/include in my system, all you have to do is
#include <header.h>
or if it resides in a sub-folder (quite often),
#include <Libname/header.h>
As long as you have set the include paths pointing at it, it should work.
To setup the include paths and directories, see example: http://zetcode.com/articles/netbeanscdevelopment/ near the end of the page.
Remember that when you hardcode paths, you need to take into consideration the current path of the file which is including the header.
Alternatively, you can use cmake & make (don't know what Netbeans uses), where you define everything your self.
You can test with full path, i.e:
#include "/home/user/project/folder/header.h
or you can test from command line and set the include path.
Hope it helps :)
I have a.cpp and a.h files in separate from the main project directory. I include a.h header file into main project using absolute path. Hot to tell c++ where it must look for a.cpp file?
The best way is to just add the cpp file to the project.
If it's outside the project or excluded from the build, you could include it in a another source file (#include "othercpp.cpp") and specify its path in the additional include directories under project settings.
But the correct approach would be to add it to the project. It doesn't have to be in the same place as other cpp files for this.
If your .cpp is in the project, it will find it. If it is not, you might work around that with the include directories, but thats just bad practice.
Visual studio normally compile all the cpp files included in the project,
so you don't need to 'find' it actually. Just drag it into current project.
Add the a.h to your projects default header file location. Do the same for your a.cpp. Add both the files to your project. You can now successfully build.
When I say add them to the default location, I mean the actual physical location that your main.cpp for the project is located as well as the header files for your project is located. If you put them anywhere else you will need to "Add additional include" directory paths for your header file.
I'm using a library with an include structure where the .h files are all in a single directory. These .h files contains a single line, a #include directive which points to the 'real' header file in specific source folder locations. The #include path in these files is relative.
So, here's an example. The directory structure is:
/project
/sources
<my .cpp files>
<my .cpp files>
...
/include
/component
foo1.h
foo2.h
/platformA/something/foo1.h
/platformB/somethingelse/foo2.h
/include/component/foo1.h contains a single line of code:
#include "../platformA/something/foo1.h"
/include/component/foo2.h contains the single line of code #include "../platformB/somethingelse/foo2.h"
In my sources, I simply have:
#include "component/foo1.h"
The header search path for my project points to /include
Now, Xcode 4 is able to find component/foo1.h in /include, but it's unable to follow the relative include path within those headers and find the 'real' foo1.h in the `/platformA/something' directory, and so on.
I suspect it's because the include paths in the top-level foo1.h file is relative to its location, but Xcode might be treating it as relative to some other location (project root or something)? FWIW, Visual Studio has no problems with an identical configuration.
What can I do to remedy this?
From your directory structure it seems that the directories platformA and platformB are placed outside the include folder. There are two possible solutions to this:
Solution A
Move these
to include folder.
Solution B
Add project/platformA and
project/platformB to the
directories where include files
should be looked for in project
settings.
Don't use relative paths. Seriously, it's implementation-defined behavior how they work, so different compilers/environments/platforms will behave differently, and in your case, Xcode is almost certainly invoking GCC or clang in some sort of "build" directory, which may or may not be a sibling to your sources directory.
It's not worth the headache.
Put platformA and platformB in include, or add another directory (say, platform-include) put them in there, and add that directory to your include path.
So I have gone through this tutorial three times:
http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx
Every time I get to the end and try to run the program, it says:
Error 1 fatal error C1083: Cannot open include file: 'MathFuncsDll.h': No such file or directory
Using a .dll was so simple in C#.
Could anyone explain to me, assuming I have a header file C:\bob.h and a corresponding dll C:\bob.dll, how I would use the functions described in the header file?
Could anyone also explain why, even if a header file is added to the header files folder with Add Existing Item, the header file cannot seem to be found?
Thank you
The 'folders' in the solution are a grouping mechanism for managin the solution, and not related to 'finding' includes or libs when compiling or linking.
If all the code isn't in the same folder, or identified using references then you may want to add include directories - with VC this is typically located under project properties/configuration properties/C C++/General/Additional Include Directories. This sets on the compiler the -I option which is to specify a path to other locations for your header files.
Say you have
C:\A.h
C:\A.cpp
C:\Project1\B.h
C:\Project1\B.cpp
And B needs to use A.
You could:
Move A files into Project 1 folder and in B.h use #include "A.h"
Change B.h to #include "../A.h"
Add addition include directories of C:\ and use #include "A.h" or #include <A.h>
Meanwhile add A.cpp and B.cpp to the project will compile them in the location they are in the file system, the object file output should all be located in the intermediate directory and usable by the linker without further issue.