How to compile .cpp with gcc (NOT g++)

This is a discussion on How to compile .cpp with gcc (NOT g++) within the Linux Programming forums, part of the Platform Specific Boards category; I tried this one, but did not work Code: gcc -x c++ prog.cpp // gives "std::basic_string" undefined reference oh, yeah, ...

  1. #1
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696

    How to compile .cpp with gcc (NOT g++)

    I tried this one, but did not work
    Code:
    gcc -x c++ prog.cpp
    // gives "std::basic_string" undefined reference
    oh, yeah, g++ keeps give me warning about "no newline at EOF" even though I have thousands of blank line at the end of code. What sup with that?
    Last edited by alphaoide; 11-25-2004 at 12:03 PM.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    But "gcc -x c++" is g++
    Isn't it?
    Where's the code?

  3. #3
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    >> But "gcc -x c++" is g++, Isn't it?
    In my practice, those two do not give equal result

    >>
    Code:
    #include <iostream>
    int main() {
        std::cout << "Hello,  world\n";
        return 0;
    }
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Try
    Code:
    gcc -x c++ hello.c -lstdc++

  5. #5
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    oh ,yeah , baby. I'm back in business. Thnx a bunch
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Quote Originally Posted by alphaoide
    oh, yeah, g++ keeps give me warning about "no newline at EOF" even though I have thousands of blank line at the end of code. What sup with that?
    Which text editor are you using to create your source code file?
    If you understand what you're doing, you're not learning anything.

  7. #7
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Quote Originally Posted by itsme86
    Which text editor are you using to create your source code file?
    kdevelop
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's a convention that the last character in a plain text file (such as source code) is a newline. Otherwise - well, output the file with cat and see for yourself where your prompt ends up.
    gcc emits a warning when this is not the case.

    Why can't you use g++?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Something's wrong with my kdevelop. I did cat, all the newlines are there at the end of file yet the compiler warning persists. I open and simply re-save with vi and it compiles with no warning.
    And I was just curious of the equivalence of g++
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    g++ is usually merely a symlink to gcc, and gcc knows to assume C++ code and the C++ standard library if it's called via that link.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User
    Join Date
    Dec 2004
    Posts
    35
    Something's wrong with my kdevelop. I did cat, all the newlines are there at the end of file yet the compiler warning persists. I open and simply re-save with vi and it compiles with no warning.
    can I just say that this is one of the most gorgeous/priceless statements ever??

    take the hint my friend, and use vim for your coding...

    VIM + gcc + beer... does life get any better?

  12. #12
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Edit the option in kdevelop to use "\r\n" for newlines rather than "\n" or whatever it uses. Tell me if that works.

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Stop bumping old threads will you!!!

  14. #14
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    It's only 10 days old!

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > It's only 10 days old!
    The original question was answered a month ago, the rest was off-topic wibble which wound itself to a close.

    See...
    11-25-2004, 08:40 PM
    oh ,yeah , baby. I'm back in business. Thnx a bunch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. segfault with gcc, but not with TC
    By koodoo in forum C Programming
    Replies: 15
    Last Post: 04-23-2007, 09:08 AM
  2. gcc not for C++?
    By tin in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2004, 08:26 AM
  3. GCC bool undefined
    By Stack Overflow in forum Linux Programming
    Replies: 3
    Last Post: 07-06-2004, 12:54 PM
  4. Replies: 4
    Last Post: 11-14-2001, 09:28 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21