This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: trying to compile


Yair Grosu wrote:

> I am new with GCC and Linux. I am trying to compile and link a 
> program and do not manage to link it since I do not know how to
> specify for it the location of the directory where the iostream
> (cout/cin) library is located.

Hmm - I tried to answer this yesterday and didn't manage too well :-)

You shouldn't have to specify the location: the compiler driver will do
that for you. Assuming, that is, you're using the correct compiler
driver. You should compile and link C++ code with 'g++' and not with
'gcc'.

This is probably the error you're getting:

    fox:~$ cat test.C
    #include <iostream>
    
    int main()
    {
        int i;
    
        std::cin >> i;
        std::cout << i;
    
        return i;
    }
    fox:~$ gcc test.C
    Undefined                       first referenced
     symbol                             in file
    cout                                /var/tmp/ccf6PsmP.o
    istream::operator>>(int &)          /var/tmp/ccf6PsmP.o
    ostream::operator<<(int)            /var/tmp/ccf6PsmP.o
    cin                                 /var/tmp/ccf6PsmP.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    fox:~$

But if you build with g++ instead of gcc, it links correctly:

    fox:~$ g++ test.C
    fox:~$

Rup.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]