Re: compiler problems pt2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



me22 wrote:
On Fri, Jan 2, 2009 at 12:01, robert watson <reswatson@xxxxxxxxx> wrote:
Thanks for the replies. Compiling my code using:

cd Desktop
g++ /home/robert/Desktop/test.c  # uses c++ compiler

Instead of:

cd Desktop
gcc /home/robert/Desktop/test.c  # uses c++ compiler

Produced no errors, and an output file called 'a.out', so I guess that means g++ keeps tabs on the libraries better.


g++ links to the C++ library; gcc does not.

I think you problem might be that you have C++ code in a .c file.
(IIRC, gcc/g++ chooses the frontend based on the file extension.)  Try
.cpp .cc .C or .cxx instead.

doesn't matter, at least for c vs. C, cpp:

[wolfram:~] andreast% cat hello2.c
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  cout << "Hello World!\n";     // prints Hello World!
  cout << "I'm a C++ program\n"; // prints I'm a C++ program
  return 0;
}

[wolfram:~] andreast% g++ hello2.c
[wolfram:~] andreast% ./a.out
Hello World!
I'm a C++ program

better would be:

[wolfram:~] andreast% g++ -Wextra -Wall -o hello2 hello2.c
[wolfram:~] andreast% ./hello2
Hello World!
I'm a C++ program

Andreas



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux