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.
Related
So there are 1 files that I want to link together, Core.h and Events.h.
Core.h is in a folder called DevEngine and the Events.h file is in a folder called Events witch is inside DevEngine.
Here are the file directorys:
Core.h = src/DevEngine/Core.h
Events.h = src/DevEngine/Events/Events.h
I have added a #include "DevEngine/Core.h" : Cannot open include file: 'DevEngine/Core.h': No such file or directory DevEngine. I don't know where I have went wrong.
I have tried: #include "../DevEngine/Core.h". That still gives me a error.
You can do #include "../Core.h".
You can also set the directories the compiler uses to search for the header files (-I option in gcc) and then use paths to those files relative to one of those directories. (See for example gcc documentation on search paths.)
This could be done differently depending on the way you are building the project.
For Visual Studio, look in this thread.
For CMake, use include_directories.
#include<apis/api1/api.h>
throws No such file or directory
i even tried moving api.h and api.cc to the main project directory and using
#include<api.h>
does the same thing even though it is in the exact same directory that the other classes use
i tried adding /apis/api1 to the compiler search path
that just crashes the compiler can someone tell me what to type into the compilers compilation line
#include <api.h>
is the way you include a system header. (That is, the header for a library installed on your system.) It does not search in the directory of the source file or in directories specified in -I command line arguments.
#include "api.h"
is the way you include your own headers. (But it will also search library header locations if it doesn't find the header locally.)
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
Some header files are present in /src/dir1/ (eg: a.h, b.h, c.h etc). My source file is present in /src/dir2/file.cpp. I used some header files that are present in /src/dir1/ but during compilation I got errors like header file not found.
Then I changed the include path like #include "../src/dir1/a.h", then error is gone in file.cpp but I get not found error in the headers files that are present in /src/dir1. Because I included the header file say a.h, that a.h included some other header files that are present in /src/dir1/ (say b.h and c.h present in a.h).
How to add the header file (a.h) in /src/dir2/file.cpp so that it should not ask to modify the include path in the header files that are present in /src/dir1/?
Note: I am using scons to build.
You can add directories to the include file search path using the -I command line parameter of gcc:
gcc -I/src/dir1 file.cpp
SCons FAQ:
How do I get SCons to find my #include files?
If your program has #include files in various directories, SCons must somehow be told in which directories it should look for the #include files. You do this by setting the CPPPATH variable to the list of directories that contain .h files that you want to search for:
env = Environment(CPPPATH='inc')
env.Program('foo', 'foo.c')
SCons will add to the compilation command line(s) the right -I options, or whatever similar options are appropriate for the C or C++ compiler you're using. This makes your SCons-based build configuration portable.
Note specifically that you should not set the include directories directly in the CCFLAGS variable, as you might initially expect:
env = Environment(CCFLAGS='-Iinc') # THIS IS INCORRECT!
env.Program('foo', 'foo.c')
This will make the program compile correctly, but SCons will not find the dependencies in the "inc" subdirectory and the program will not be rebuilt if any of those #include files change.
It's not found because it's not there. You have one extra level of indirection. A file in "/src/foo/" would include a file in "/src/bar/" with "include ../bar/the_file"
In other words, in your example, there is no "../src/" relative to dir1 or dir2. The relationship is "dir1/../dir2" or "dir1/../../src/dir2"
To see this for yourself, make dir1 your current directory (chdir /src/dir1) and compare the difference betwee "ls .." and "ls ../src". The second ls will not work but the first one will.
Make sense? hope that helps
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 :)