Results 1 to 8 of 8

Thread: gcc #include file path OK for C, doesn't work for C++

  1. #1
    Junior Member
    Join Date
    Jul 2006
    Posts
    4

    gcc #include file path OK for C, doesn't work for C++

    Hi!
    Using KNOPPIX 5.0.1CD, the gcc compiler for C has no trouble finding stdio.h. The C++ compiler cannot find iostream.

    1. Do you have any suggestions for a work-around?
    2. I'm going to be remastering this version of KNOPPIX to have some tools that aren't in the standard version, so I could change path variables, etc. What needs to be changed?

    Thanks,
    Fred

  2. #2
    Member registered user
    Join Date
    Mar 2005
    Posts
    77

    C++ compiler

    Have you tried GCC? i.e.
    g++ nameofprogram.cp -o anyname

  3. #3
    Junior Member
    Join Date
    Jul 2006
    Posts
    4

    GCC with C++ problem

    Thanks, WaKa!
    What I did was the simple "hello, world!" program in C and C++, using exactly the format you suggested.

    For C, it worked absolutely as expected, so I was surprised when it couldn't find iostream for the C++ version of the program (using cout << "Hello, world!" << endl; ), and I got the error message that ostream was not defined in this function! I gave it this:

    #include <iostream>

    for C++, just like I gave it:

    #include <stdio.h>

    for the C case. I tried the alias for gcc (g++), as well. If I specifically gave the absolute path to iostream it worked.
    Since this is a Live CD, however, I'd have to re-master to add a PATH or an alias.

    So suggestions are still welcome!

    --Fred

  4. #4
    Member registered user
    Join Date
    Mar 2005
    Posts
    77

    C++

    use this:

    #include <iostream>

    int main()
    {
    std::cout << "Hello, world!" << std::endl;
    return 0;
    }

  5. #5
    Junior Member
    Join Date
    Jul 2006
    Posts
    4

    GCC and C++

    Thanks for your reply, WaKa.

    The problem is that gcc can't find the #include file iostream, not that it's using the wrong namespace.

    Whe I use the -v (verbose) output, it tells met that it is, in fact, looking in a non-existent directory. - many directories deeper than the real one.

    Does the program you gave actually work on your copy of KNOPPIX 5.0.1CD? If so, then I'll have to try another download.

    Thanks,
    Fred

  6. #6
    Junior Member
    Join Date
    Jul 2006
    Posts
    4

    C++ path issue

    FYI, here's the response to the gcc invocation:
    knoppix@1[~]$ gcc -v test.cpp -o test
    Using built-in specs.
    Target: i486-linux-gnu
    Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
    Thread model: posix
    gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
    /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/cc1plus -quiet -v -iprefix /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/ -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=i686 -auxbase test -version -o /tmp/cclr3aiv.s
    ignoring duplicate directory "/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4"
    ignoring duplicate directory "/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/i486-linux-gnu"
    ignoring duplicate directory "/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/backward"
    ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
    ignoring duplicate directory "/usr/lib/gcc/i486-linux-gnu/4.0.4/include"
    ignoring nonexistent directory "/usr/include/i486-linux-gnu"
    #include "..." search starts here:
    #include <...> search starts here:
    /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4
    /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/i486-linux-gnu
    /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/backward
    /UNIONFS/usr/bin/../lib/gcc/i486-linux-gnu/4.0.4/include
    /usr/local/include
    /usr/include
    End of search list.
    GNU C++ version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3) (i486-linux-gnu)
    compiled by GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3).
    GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129331
    test.cpp: In function 'int main()':
    test.cpp:8: error: 'cout' was not declared in this scope
    test.cpp:8: error: 'endl' was not declared in this scope

    As I read this, gcc is looking in a bunch of wrong directories for the C++ include files.

    --Fred

  7. #7
    Junior Member registered user
    Join Date
    Jan 2006
    Location
    Scottsdale, Arizona
    Posts
    10
    Post your source code. I think it is that you are not using the STD namespace.

    You should do this in your file:

    #include <iostream>

    using namespace std;

    int main (void)
    {
    cout << "Hello World!" << endl;

    return 0;
    }

    See if that works. If that doesn't work, post your source.

  8. #8
    Member registered user
    Join Date
    Mar 2005
    Posts
    77
    Code:
    knoppix@1[~]$ gcc -v test.cpp -o test
    gcc is the compiler for C
    g++ is the compiler for C++
    test(name of program) is not a unique name because it conflicts with bash.
    use this
    g++ -v test.cpp -o test_1 (or what ever you like)

Similar Threads

  1. Desktop File Folders don't work
    By Keithj in forum Hdd Install / Debian / Apt
    Replies: 10
    Last Post: 09-10-2005, 05:55 AM
  2. Loading configuration file won't work
    By sfackler in forum General Support
    Replies: 0
    Last Post: 08-31-2005, 03:32 AM
  3. LiveCD Install -- File Path Help
    By tilleyrw in forum General Support
    Replies: 1
    Last Post: 04-29-2005, 04:18 AM
  4. Can't get ATI drivers to work from the RPM file, need help
    By c0ns7ruc7 in forum Hardware & Booting
    Replies: 2
    Last Post: 11-10-2004, 10:35 PM
  5. Replies: 5
    Last Post: 04-25-2003, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Samsung Galaxy Tab A8 10.5

Samsung Galaxy Tab A8 10.5" SM-X200 128GB Wifi Only Tablet Open Box

$149.99



Genuine Samsung Book Cover Keyboard for 14.6

Genuine Samsung Book Cover Keyboard for 14.6" Galaxy Tab S8 Ultra | S8 Ultra 5G

$89.99



Samsung Galaxy Tab A9 (X110) 64GB 4GB RAM International Version (New) picture

Samsung Galaxy Tab A9 (X110) 64GB 4GB RAM International Version (New)

$129.99



Samsung - S Pen Creator Edition - White picture

Samsung - S Pen Creator Edition - White

$40.00



Samsung Galaxy 12.4 Inch EF-DT730 Slim Keyboard For  S7+ | S7 FE | S8+ | S8+ 5G picture

Samsung Galaxy 12.4 Inch EF-DT730 Slim Keyboard For S7+ | S7 FE | S8+ | S8+ 5G

$39.99



Samsung Galaxy Chromebook Go, 14-inch, 32GB, Unlocked All Carriers - Silver picture

Samsung Galaxy Chromebook Go, 14-inch, 32GB, Unlocked All Carriers - Silver

$99.95



Samsung 16GB 2Rx4 PC3-12800R M393B2G70BH0-CK0 DDR3 RDIMM - SERVER RAM picture

Samsung 16GB 2Rx4 PC3-12800R M393B2G70BH0-CK0 DDR3 RDIMM - SERVER RAM

$8.90



Samsung 27

Samsung 27" FHD Monitor 75 hz, IPS LED, LF27T350FHNXZA *READ DISCRIPTION*

$74.99



Tempered Glass Screen Protector For Samsung Galaxy Tab S9/S9 FE/S9 Plus/S9 Ultra picture

Tempered Glass Screen Protector For Samsung Galaxy Tab S9/S9 FE/S9 Plus/S9 Ultra

$10.95



Samsung Laptop Chromebook XE303C12-A01US, Dual-Core 1.7GHz 4GB 16GB picture

Samsung Laptop Chromebook XE303C12-A01US, Dual-Core 1.7GHz 4GB 16GB

$39.99