CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: gcc errors

  1. #1
    Join Date
    Mar 2000
    Location
    Oxford, UK.
    Posts
    352

    Wink gcc errors

    Hi folks! I have to use gcc now. What fun this is. At the moment I can't even get hello world to build!

    Code:
    #include <iostream>
    
    int main(void) {
    
       std::cout << "hello world" ;
    
    }
    gcc says this:
    undefined reference to 'std::cout'

    so I guess I need to link to a library. How do I do this?

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    The command name g++ is aliased to the C++ compiler.

    Quick Start:

    1) Switch to the directory in which hello.cpp is.
    2) g++ hello.cpp -O3 -Wall -o hello.out
    3) ./hello.out

    For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

    I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

    Don't lose heart, the GNU compiler collection works.

    Good luck.

    Chris.

    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    So here is that promised Makefile.

    Place it in the directory of your source code, make sure the filename in the Makefile agrees with the sample file that you want to create and just type the command make.

    In order to work effectively with the GNU compiler collection, you must eventually familiarize yourself with the GNU make facility as well as the myriad of compiler switches of gcc/g++.

    Cheers.

    Chris.

    You're gonna go blind staring into that box all day.

  4. #4
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Forgot the Makefile attatchment...
    Chris.
    Attached Files Attached Files
    You're gonna go blind staring into that box all day.

  5. #5
    Join Date
    Mar 2000
    Location
    Oxford, UK.
    Posts
    352
    Originally posted by dude_1967
    The command name g++ is aliased to the C++ compiler.

    Quick Start:

    1) Switch to the directory in which hello.cpp is.
    2) g++ hello.cpp -O3 -Wall -o hello.out
    3) ./hello.out

    For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

    I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

    Don't lose heart, the GNU compiler collection works.

    Good luck.

    Chris.

    Thanks for you assistance.
    So this is better.
    What's the diff between entering gcc hello.cpp and g++ hello cpp?
    when I try to run it ./hello.out it says:

    error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory.


  6. #6
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    c94wjpn:

    I actually always thought that gcc would alias both the C compiler as well as the C++ compiler, using the file extension to determine the appropriate language (.cc, .cpp, etc for C++).

    I used GCC heavily in the early '90s and stopped until about a year or two ago. When I returned to GCC, I also had problems just like yours. I then started using gcc for C-sources and g++ for C++-sources. This seems to be necessary for the newest GCC also.

    Can any other guru explain the aliasing convention of gcc and g++?

    Chris.

    You're gonna go blind staring into that box all day.

  7. #7
    Join Date
    Mar 2000
    Location
    Oxford, UK.
    Posts
    352
    Originally posted by dude_1967
    The command name g++ is aliased to the C++ compiler.

    Quick Start:

    1) Switch to the directory in which hello.cpp is.
    2) g++ hello.cpp -O3 -Wall -o hello.out
    3) ./hello.out

    For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

    I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

    Don't lose heart, the GNU compiler collection works.

    Good luck.

    Chris.

    Thanks for you assistance.
    So this is better.
    What's the diff between entering gcc hello.cpp and g++ hello cpp?
    when I try to run it ./hello.out it says:

    error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory.


  8. #8
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Someone wrote:
    >>>
    Can any other guru explain the aliasing convention of gcc and g++?
    <<<

    Well, the ORIGINAL intent of gcc was to be a c compiler; the acronym stood for GNU C Compiler. They expanded that vision to include other compilers; the acronym now stands for GNU Compiler Collection. They want each compiler to be more standalone now, while gcc can be used to call any of them. Note that you can still use gcc to compile/link c++ programs ... you just will need to explicitly tell gcc which libraries to link with. I use g++ because g++ uses the proper includes and libraries automatically.

  9. #9
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Someone wrote:
    >>>>>
    error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory
    <<<<<

    What OS are you using? You probably need to make sure that the dynamic library loader environment variable is set; each OS has a different notation for this. HP-UX uses SHLIB_PATH; AIX uses LIBPATH; everything else, I think, uses LD_LIBRARY_PATH. Anyway, if you did not change the prefix [while running configure], then everything should have been installed in /usr/local/lib [and the includes in /usr/local/include/g++-v3]. Assuming everything was installed properly, you now need to make sure that your LD_LIBRARY_PATH [or equivalent] has /usr/local/lib in it.

    --Paul

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured