Advertisement

trouble with g++ and -I include/

Started by April 29, 2004 07:30 PM
9 comments, last by clayasaurus 20 years, 6 months ago
hi, i'm having trouble including my own directory with g++. my file structure is like this include/cInput.h source/cInput.cpp first, i'll say, when I do g++ -c source/cInput.cpp with a header like "../include/cInput.h" located inside the file it works. but when i change that to "cInput.h" and do g++ source/cInput.cpp -I include/ -I /usr/include i get a ton of errors about < cmath > located inside of < iostream >, like this ...

g++ -c source/cInput.cpp -I include/ -I /usr/include/ -I /usr/include/c++/3.2.3/ -I /usr/include/c++/3.2.3/backward/ -I /usr/include/c++/3.2.3/bits
In file included from /usr/include/c++/3.2.3/bits/locale_facets.tcc:41,
                 from /usr/include/c++/3.2.3/locale:46,
                 from /usr/include/c++/3.2.3/bits/ostream.tcc:37,
                 from /usr/include/c++/3.2.3/ostream:275,
                 from /usr/include/c++/3.2.3/iostream:45,
                 from source/cInput.cpp:17:
/usr/include/c++/3.2.3/cmath: In function `float std::acos(float)':
/usr/include/c++/3.2.3/cmath:99: `::acosf' undeclared (first use here)

what am i doing wrong? thx. [edited by - clayasaurus on April 29, 2004 9:03:32 PM]
just a guess...
have you tried not putting in the -I/usr/* paths in the command line? might be a prob with that, sometimes version conflicts also make errors like that
Advertisement
i tried g++ -c source/cInput.cpp -I include/ -I /usr/* with no success yet. thx anyway.

btw, i'm pretty sure i wont' get any problems if i don't include < iostream > at all , but i hope there's another way.

[edited by - clayasaurus on April 29, 2004 10:30:45 PM]
I think the AP''s trying to say that you should try running g++ without those -I/usr/..... include paths, since they might be causing version conflicts.

What does "g++ --version" tell you?
My stuff.Shameless promotion: FreePop: The GPL god-sim.
well, i have tried not putting the /usr/* stuff on the command line and i still get the same problems.


g++ --version is
g++ (GCC) 3.2.3Copyright (C) 2002 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
another thing i might want to do is to #include < cInput.h > , but the problem with this is that every time i do make install it replaces all the .h files, and rebuilds the whole library every time. any way around that? thx.
Advertisement
ok, i figured out a quick hack around this problem

all i had to do was go to /usr/include/c++/version/bits/locale_facets.tcc and change cmath to math.h . heh. oh well.
(shell dependent environment declaration - man your sh for more info; info gcc for more information about valid environment variables that alter gcc/g++ behavior)

export CPLUS_INCLUDE_PATH=/home/foo/bar/qux/include:/some_non_standard_user_defined/stable_include_search/include

The problem I can see with your original post is that you say you have two dirs, source/ & include/. Not a problem in and of itself but consider the following:

g++ -c source/cInput.cpp -I ./include/
^-gotcha if you don''t do this*

I assume that will solve your problem? A better solution from a clarity standpoint would be to define a variable for your includes with full search path; see above.

(The above does assume that you are issuing make/g++/gcc in the current root of your build dir, ie ../../../test
test:
./source
./include
...etc files & stuff

*gotcha, ie: /usr/include but perhaps your gcc is /usr/local/include, version conflict possible, etc. Hope this makes sense...
quote: Original post by Anonymous Poster
(g++ -c source/cInput.cpp -I ./include/
^-gotcha if you don''t do this*
*gotcha, ie: /usr/include but perhaps your gcc is /usr/local/include, version conflict possible, etc. Hope this makes sense...


D''oh - formatting issues:
the "gotcha" is the -I include (bad) vs. -I ./include (good)
ok, i *think* I finally figured out what is wrong, because now i got it to compile with cmath. the problem was that in my own include/ dir there was a file called math.h which probably conflicted with the standard math.h and therefore all these things were not defined. well, i just changed the name of my own math.h and things *seem* all dandy.

This topic is closed to new replies.

Advertisement