Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > why is include not working? - beginner question

Reply
Thread Tools

why is include not working? - beginner question

 
 
Jason
Guest
Posts: n/a
 
      10-17-2009
I am a beginner with c++. I'm running g++ from the command line in
Ubuntu. I found everything working fine except that when I try to
include a *.h file, I can't get it to work.

I downloaded SQLAPI and am trying to include the SQLAPI.h file at the
beginning of a file called "my_file.cpp". The path to the SQLAPI.h
file is "foo/SQLAP/include" and the path to "my_file.cpp" is "foo/
my_file.cpp". I attempted to include the file like this (what did I do
wrong?):

#include <stdio.h> // for printf
-I<SQLAPI/include/SQLAPI.h> // main SQLAPI++ header

int main(int argc, char* argv[])
{
SAConnection con; // create connection object

try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(...etc...
...etc...
Thank you!
 
Reply With Quote
 
 
 
 
Joshua Maurice
Guest
Posts: n/a
 
      10-17-2009
On Oct 16, 6:52*pm, Jason <(E-Mail Removed)> wrote:
> I am a beginner with c++. I'm running g++ from the command line in
> Ubuntu. I found everything working fine except that when I try to
> include a *.h file, I can't get it to work.
>
> I downloaded SQLAPI and am trying to include the SQLAPI.h file at the
> beginning of a file called "my_file.cpp". The path to the SQLAPI.h
> file is "foo/SQLAP/include" and the path to "my_file.cpp" is "foo/
> my_file.cpp". I attempted to include the file like this (what did I do
> wrong?):


> -I<SQLAPI/include/SQLAPI.h> // main SQLAPI++ header


Is that literally in your source file?

Try
#include "SQLAPI.h"
in your source file, and try putting
-ISQLAPI/include
on the command line. (Probably something like
-I${SQLAPI}/include
where SQLAPI is an environmental variable which points to "the SQL
folder".)
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-17-2009
Jason wrote:
> I am a beginner with c++. I'm running g++ from the command line in
> Ubuntu. I found everything working fine except that when I try to
> include a *.h file, I can't get it to work.
>
> I downloaded SQLAPI and am trying to include the SQLAPI.h file at the
> beginning of a file called "my_file.cpp". The path to the SQLAPI.h
> file is "foo/SQLAP/include" and the path to "my_file.cpp" is "foo/
> my_file.cpp". I attempted to include the file like this (what did I do
> wrong?):
>
> #include <stdio.h> // for printf
> -I<SQLAPI/include/SQLAPI.h> // main SQLAPI++ header


Is that in your source code? Remove it. That's likely supposed to be
in your command line, not to mention that you didn't actually include
the needed header:

#include <SQLAPI.h>

What beginner's book are you reading that doesn't explain such simple
concepts?

>
> int main(int argc, char* argv[])
> {
> SAConnection con; // create connection object
>
> try
> {
> // connect to database
> // in this example it is Oracle,
> // but can also be Sybase, Informix, DB2
> // SQLServer, InterBase, SQLBase and ODBC
> con.Connect(...etc...
> ...etc...
> Thank you!


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      10-17-2009
On Oct 16, 8:01*pm, Victor Bazarov <(E-Mail Removed)> wrote:
> What beginner's book are you reading that doesn't explain such simple
> concepts?


Thank you. I know this seems just too simple. Problem is, I've been
searching for some time and still have not found documentation on
doing something like -I${environment_variable}/include in the command
line. Would you mind pointing me to this documentation? And how does
this statement fit? I tried putting the #include statement in the
source file like you said (#include "SQLAPI.h" ) and using the -I
option in the command line:

jrl:~$ g++ my_source_file.cpp -I${SQLAPI}/include

also tried:

jrl:~$ g++ -I${SQLAPI}/include my_source_file.cpp

Still, I get:

my_source_file.cpp:2:44: error: SQLAPI.h: No such file or directory

I wish this did not seem like such a lame question, but I just can't
find the answer - not sure where to look in beginner books online.

Thank you!


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      10-17-2009
On Oct 17, 5:09 am, Jason <(E-Mail Removed)> wrote:
> On Oct 16, 8:01 pm, Victor Bazarov <(E-Mail Removed)> wrote:


> > What beginner's book are you reading that doesn't explain
> > such simple concepts?


> Thank you. I know this seems just too simple. Problem is, I've
> been searching for some time and still have not found
> documentation on doing something like
> -I${environment_variable}/include in the command line.


Have you read the documentation of your compiler? How to invoke
the compiler depends on the implemenation: using -I or /I seems
to be an almost universal choice for specifying include paths
(i.e. telling the compiler where to look for included files).
Some compilers allow the option and the path to be separated by
a space, others not. (In practice, almost all of the compilers
which use /I also understand -I, and all those which allow the
space accept the option without it, so it's common here to
simply say -Ipath, which works with pretty much all compilers,
even if it isn't the "preferred" form for some.)

I will warn you, however, that most compiler documentation isn't
for beginners. And that it's a point that most beginners' books
do seem to ignore. (On the other hand, what beginners' book
could have given you the idea that -Iwhatever was legal in the
source code?)

> Would you mind pointing me to this documentation? And how does
> this statement fit? I tried putting the #include statement in
> the source file like you said (#include "SQLAPI.h" ) and using
> the -I option in the command line:


> jrl:~$ g++ my_source_file.cpp -I${SQLAPI}/include


> also tried:


> jrl:~$ g++ -I${SQLAPI}/include my_source_file.cpp


> Still, I get:


> my_source_file.cpp:2:44: error: SQLAPI.h: No such file or directory


How is $SQLAPI defined in your shell?

For starters, what you have to do (with g++, but this also works
with most other compilers) is -Ipath, where path is the
specification of where the compiler should look for the files,
in this case, the path where your SQLAPI product installed the
header files. (Probably something like /opt/SQL/include or
/usr/local/include, depending on the system.) But it's a pain
to have to type this in every time, and to keep in mind where
all of the different products are installed on different
systems, so it's usual to set up an environment variable for
each product in your login file, pointing to its root, and use
this. Read the documentation of your shell for this.

> I wish this did not seem like such a lame question, but I just
> can't find the answer - not sure where to look in beginner
> books online.


The problem is that you're dealing with several different
layers: the shell which interprets your command line, your
compiler, and the language. You need to know all three.

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Easiest way to include a form on multiple pages? (Beginner Question) jan Javascript 6 05-04-2006 06:35 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 7 02-03-2005 02:47 PM



Advertisments