Cannot open include file "sqlapi.h" in C++? - c++

I am trying to connect c++ with SQLBase. After building my project I get an error as
" Cannot open include file: 'SQLAPI.h': No such file or directory ".
#include <stdio.h>
#include <SQLAPI.h> // main SQLAPI++ header
#include <sbAPI.h>
Can someone please tell me why am I getting this error and how to fix it?

The file "SQLAPI.h" is not in the include path. You need to add the path to the header files to the compilation flags.
If you are using GCC then add a flag -I like this:
g++ -I/path/to/headers <rest of arguments>
See http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html for the -I option.
If using a Makefile, change CFLAGS or CXXFLAGS to add the -I option.
If using Visual Studio, go into the project properties dialog, select "Configuration Properties" and "VC++ Directories", and modify the "Include Directories" property. (Based on Visual C++ 2010 Express, should be similar in older versions.)

For VS 2008 C++ you need to set the following Project options:
[Project options dialog]
C\C++
Additional Include Directories = C:\Dev\Tools\Win32\SQLApi\3.8.2\include
Linker
General
Additional Library Directories - C:\Dev\Tools\Win32\SQLApi\3.8.2\lib
Input
Additional Dependencies - sqlapis.lib
Warning: example path provided!
Instead of 'C:\Dev\Tools...' set your actual SQLAPI++ library instance location!

I am learning C in Microsoft Visual C++ Express platform.
A way may work:
You should copy your own header files(like SQLAPI.h) to your solution file.
Obviously, it is a complicated way when you want to add much more of your own header files. You have to copy many times. There must be one simpler way to solve this problem by using system path or something else. But, I didn't solve it in this method totally.
Last, good luck. Hope it will be helpful.

Related

I can't include a boost header file mapped_file.hpp in my project

I need to include "\boost\iostreams\device\mapped_file.hpp" in my project. I tried:
#include <\boost\iostreams\device\mapped_file.hpp>,
but it couldn't work. Therefore, I used:
#include "C:\path\boost\iostreams\device\mapped_file.hpp".
As a result, the system could find "mapped_file.hpp" file. However, when I build the project, the system complains:
C:\path\boost\iostreams\device\mapped_file.hpp(14): fatal error C1083:
Cannot open include file: 'boost/config.hpp': No such file or directory
This tells me the way I fixed the first error is incorrect.
I have another project downloaded from a repository that uses boost library. This project is already built successfully in my PC. Everything for the boost library in my PC comes from this project, and the header file I need to use is located in "C:\path\boost\iostreams\device\mapped_file.hpp". In this case, how should I add a path or include "\boost\iostreams\device\mapped_file.hpp" to fix my current problem?
Thanks in advance!
I need to include "\boost\iostreams\device\mapped_file.hpp" in my project.
Actually, no, you don't. You might need to include "boost\iostreams\device\mapped_file.hpp" (no leading slash) in your project, but that leading slash will make it impossible for the compiler to find the header file (unless you installed boost to your root directory – rather rare).
In addition, make sure the compiler knows to look in C:\path\ for included headers. As discussed in the comments, this can be done in Visual Studio 2012 via Project properties → C/C++ → General → Additional Include Directories.

No such file (header file) error

I want to include a header file. I am working in a C++ environment, (C++11, Windows OS, Netbeans 7.3.1 IDE, Cygwin_4.x tool collection). I do not know how I setup the environment/IDE (I did it 6 months ago). I do not understand the fundamentals of the C++ build process or Cygwin related issues either, so I might have to fill in the gaps with some other references/documentation (on what specifically, I'm not sure).
My ultimate objective is to be able to include header files using a syntax that does not require the full file path. I want to write something terse, like:
#include "src\stuff\blah.h" //or even better: #include "blah.h"
The only way I can get my program to compile at all is by using the full file path, like this:
#include "C:\NetBeansProjects\Project1\src\stuff\blah.h"
And, I can only compile once using the full path. If I try to rebuild, it will bomb with the *** multiple target patterns. Stop. error. There are workarounds for this error; those being either 1) deleting the build and dist folders between each rebuild (yikes?), or 2) following this 16 step setup process.
I do not want to follow either of those workarounds because they do not appear to deliver what I want. How can I setup my environment to achieve what I want...of being able to include header files without using full paths?
Thanks to DanielKO for this answer.
In my case, I was able to include with the syntax:
#include "../stuff/blah.h"
I did not have to configure anything under the "Code Assistance" section for the C++ compiler.
All of my code is under "src" as the parent directory in my NetBeans project. It seems that the full path of the file is not required, and the only directory that must be referenced is the lowest level subdirectory (in my case, "stuff").
In NetBeans I've added the path to the list of libraries:
Go to Properties->Select C++->Select 'include libraries'->'Add'
Now: Add the path of the project folder with option "absolute"
Go to Properties->Select C++->Select 'Additional library directories'->'Add'
Now: Add the path of the project folder with option "absolute"
It's very obscure to me why the project doesn't recognize "own" header files.

Cannot open include file with Visual Studio

I have recently gone from Code::Blocks to Visual Studio, and in Code::Blocks one could just add a class and then include it straight away. However, whenever I do the same in Visual Studio with the following statement:
#include "includedFile.h"
or
#include "include/includedFile.h"
It doesn't work and instead I get the error:
cannot open include file: 'includedFile.h'; no such file or directory.
Is there some box or setting that I have to tick? Or do I have to add each header as a dependency manually?
Here is the code for the class in question:
Public.h:
#pragma once
class Public
{
public:
static const int SCREEN_WIDTH=1000;
static const int SCREEN_HEIGHT=1250;
Public(void);
~Public(void);
};
Public.cpp:
#include "Public.h"
Public::Public(void)
{
}
Public::~Public(void)
{
}
How it is being included:
#include "Public.h"
I had this same issue going from e.g gcc to visual studio for C programming. Make sure your include file is actually in the directory -- not just shown in the VS project tree. For me in other languages copying into a folder in the project tree would indeed move the file in. With Visual Studio 2010, pasting into "Header Files" was NOT putting the .h file there.
Please check your actual directory for the presence of the include file. Putting it into the "header files" folder in project/solution explorer was not enough.
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
And be sure that your Configuration and Platform are the active ones. Example: Configuration: Active(Debug) Platform: Active(Win32).
You need to set the path for the preprocessor to search for these include files, if they are not in the project folder.
You can set the path in VC++ Directories, or in Additional Include Directories. Both are found in project settings.
By default, Visual Studio searches for headers in the folder where your project is ($ProjectDir) and in the default standard libraries directories. If you need to include something that is not placed in your project directory, you need to add the path to the folder to include:
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
You can, also, as suggested by Chris Olen, add the path to VC++ Directories field.
I found this post because I was having the same error in Microsoft Visual C++. (Though it seems it's cause was a little different, than the above posted question.)
I had placed the file, I was trying to include, in the same directory, but it still could not be found.
My include looked like this: #include <ftdi.h>
But When I changed it to this: #include "ftdi.h" then it found it.
If your problem is still there it's certainly because you are trying to compile a different version from your current settings.
For example if you set your Additional Include Directories in Debug x64, be sure that you are compiling with the same configuration.
Check this: Build > Configuration Manager... > There is problably something like this in your active solution configuration: Debug x86 (Win32) platform.
For me, it helped to link the projects current directory as such:
In the properties -> C++ -> General window, instead of linking the path to the file in "additional include directories". Put "." and uncheck "inheret from parent or project defaults".
Hope this helps.
I tried the other answers here as well, but my problem had nothing to do with the include paths or files missing incorrect #includes. I had two configurations, each set to the exact same include directories. One configuration could resolve the includes, the other could not.
After selecting my project and going to Project -> Properties, I selected both configurations through the Configuration dropdown -> Multiple Configurations... option. Comparing the two I found that C/C++ -> Language -> Conformance Mode was different. The "incorrect" configuration had a value of Default for some reason, and switching it to Yes or No allowed the paths to be resolved.
TL;DR: If you have one configuration with the same include directories but the other isn't finding the files, I suggest to try comparing the configurations.
If you've tried the other answers and your include file still can't be found, here are some additional debugging steps and sanity-checks:
Ensure that you are building to a platform that is supported by your code. (If not, consider removing this platform as a target)
Verify that the filename/path is correct. Modify your source code to #include the whole absolute path of the header file instead, and see if the file can be found now. If not, copy-paste the path from your source code into a command line to validate that the file exists at that full path with no typos. Open the header file to ensure you have read access. (Change the source code back when done.)
If you've already added the path to Additional Include Directories, try clicking the drop-down combo box for Additional Include Directories, and select <Edit...>. This will show you evaluated values of paths. (If it does not show the correct evaluated values, variables in your path might not be set. Click Macros>> to see variables.) Copy-paste the evaluated path into windows explorer to validate that the path exists.
Create a new empty C++ "Windows Console Application" project. Set just the one Include Directory, and #include just the one file in your main.cpp, and see if that builds.

Eclipse cdt: Includes header file correct, compiles, but highlights source code: "Unresolved inclusion"

I have a project that uses a shared library from another project.
In project settings I put the correct include paths and library for the GCC and G++ compiler (-L and -l option). It all compiles well, no problems here.
But the source code is not analyzed correctly.
My included headerfile (that is located in the other project) is marked as "Unresolved inclusion and everywhere I use something from it, the source is highlighted as well.
#include "myHeader.h"
Any ideas? thanks!
The one that you are missing here (probably) is, telling the indexer where to look for those headers.
I normally manage my own Makefile, so I do not know how to make it work for both the eclipse managed makefile and for the Indexer. Probably you will find that the solution below will fix both.
On the solution; right click on the project in the Project explorer ( or resource explorer ), and select Properties. Now under "C/C++ General" > "Paths and Symbols", click on Includes tab and select "GNU C++". Then on the right side, you can add various include paths ( similar to the -I option on gcc/g++ ) by clicking on "Add..." button.
Once you apply and click OK, the indexer will take a while to clear those unresolved object.
A header should be included like this
#include "myHeader.h"
or if it's a standard lib header:
#include <string>
everything else is invalid.
Remember to enable the Providers in the "Preprocessor Include Paths, Macros, etc.".

Error can not open source file "..."

I'm using VS2010 (downloaded via dreamspark) and although I can open the #include file by right clicking on it and pressing on Open Document, it complains "Error can not open source file "..."" which seems rather absurd. I'm using Qwt with Qt this time around and I'm specifically having the problem for:
#include <qwt_counter.h>
#include <qwt_plot.h>
(And I am using the "<>"); not sure how to make those appear properly in the code above.
Thanks in advance.
As Neil indicated, try using quotes instead of the <> characters around the filename. When using the quotes, MSVC will look in the same directory as the file the #include is in for the specified file, then if it's not found there will look in the directories specified by the include path. When the filename is surrounded by <> characters, the current file's directory isn't looked at - the compiler goes right to the include path.
See http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx for details.
Note that this is an implementation dependent behavior - it might not apply to other compilers.
If that doesn't help, make sure that your include path contains the directory that the file is located in by setting the "Include Directories" property appropriately:
http://msdn.microsoft.com/en-us/library/t9az1d21.aspx
Finally, you might be using a makefile project (I'm not sure how common it is for Qt projects to continue to use qmake when built from VS) , in which case you'll need to perform whatever configuration is necessary in the make file(s) or parameters passed on the command line that invokes the makefiles.
Is the path where these files are located either the same as that of this source file, or included in the "additional include directories" in your project settings?
Project -> properties -> c/c++ section -> additional include directories.
If they are located in a subdirectory of the source file you're editing or of one of the additional include directories (I think) you can also include them with:
#include <path_to_file_1/qwt_counter.h>
#include <path_to_file_2/qwt_plot.h>
[edit]
or of course what neil says
[/edit]
It turned out there was a circular linking happening and I had all my code in a .h file. I split it up and added the corresponding .cpp file, now everything works fine.