CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: STL and Linux

  1. #1
    Join Date
    Dec 2001
    Posts
    199

    Question STL and Linux

    Hi,

    I am trying to port my current C++ and C skills to Linux Programming. I have successfully created the standard Hello World starting project in C for linux using both files and standard output.

    I am trying to do something simular using standard C++ libraries, I tried to use the iostream template class in the STL library, I don't whether it is supported in Linux however I can seem to use #include <iostream> without a linking error being generated. The linker throughs an error "Undefined reference" when I write the complete Hello World program:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
         cout << "\n Hello World";
    }
    I am at the moment thinking the problem is that I am not linking the program with the required stl library, however I have no idea how to do this in Linux.

    I have look through the standard included documentation but cannot find a reference of the libraries included in Linux (Red Hat 8.0), does any know of a good reference on the C++ libraries in Linux? Is this my problem or does Linux not support STL?

    I am new to Linux programming so I am at the moment only really looking for a good reference site, thanks in advance.

    KnNeeded

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,019
    How are you building the system? Use g++ instead of gcc
    Succinct is verbose for terse

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by cup
    How are you building the system? Use g++ instead of gcc
    Well...gcc is the GNU compiler suite which provides frontends for C, C++, Java, Fortran etc. as well as these libraries. g++ is the traditional name of the C++ compiler which is part of the gcc suite...

    So, I do not see what you mean?

  4. #4
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    There is not a library for the STL. The STL is (usually) only source code and exists entirely in the headers. It is called a library but there is not a library for it. At least not for the most popular implementations of the STL. The STL is part of the C++ language, so it is supported by the Linux compiler.

    I have not used gcc much but I am nearly certain that what was said by cup is what you need and you probably already have the problem solved. As I recall, the default language that gcc recognizes is C and the default language that g++ recognizes is C++. They are essentially the same program except for minor differences such as that. I recall having a similar problem; in a Windows environment, I assumed that a file with a cpp extension would be compiled as a C++ program, but it was not. I got a compile error using gcc (I think) that went a way when I compiled using g++ (I think).
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Andreas Masur
    Well...gcc is the GNU compiler suite which provides frontends for C, C++, Java, Fortran etc. as well as these libraries. g++ is the traditional name of the C++ compiler which is part of the gcc suite...
    I am nearly certain that the default language for gcc is C.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    Dec 2001
    Posts
    199
    Thanks Guys I will check it out

  7. #7
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Do not pass void to functions in C++.

    Sorry, I know that doesn't fix your problem but it is SO annoying when people do that =/

    I'm wierd

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by Sam Hobbs
    There is not a library for the STL. The STL is (usually) only source code and exists entirely in the headers. It is called a library but there is not a library for it. At least not for the most popular implementations of the STL.
    That is not true...one of the most popular STL implementation uses an library and/or a dll - STLport. I do not know much about others - Dinkumware, which is part of the IDE, might be different, however, I never used anything different than STLport...

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by Sam Hobbs
    I am nearly certain that the default language for gcc is C.
    Well...gcc stands for GNU Compiler Collection, which simply acts as a front end for the underlying compilers it contains. The former name was GNU C Compiler, at that time it was only a simple C compiler...

  10. #10
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Andreas Masur
    That is not true...one of the most popular STL implementation uses an library and/or a dll - STLport. I do not know much about others - Dinkumware, which is part of the IDE, might be different, however, I never used anything different than STLport...
    I am quite surprised that this is the first time I have heard of STLport and that it uses libraries. I have seen Dinkumware mentioned in the C++ language newsgroup but not STLport.
    Originally posted by Andreas Masur
    Well...gcc stands for GNU Compiler Collection, which simply acts as a front end for the underlying compilers it contains. The former name was GNU C Compiler, at that time it was only a simple C compiler...
    Yes but what is the default language for gcc? The meaning of gcc is not very relevant; the default language is.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  11. #11
    Join Date
    Dec 2003
    Posts
    99
    Originally posted by kasracer
    Do not pass void to functions in C++.

    Sorry, I know that doesn't fix your problem but it is SO annoying when people do that =/

    I'm wierd

    Why so ?

    Sincerely,

  12. #12
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Originally posted by nsh123
    Why so ?

    Sincerely,
    Because the C++ standard says NOT to. A function requiring no arguements (you don't want to send any to main) does not need to be sent void. That is C, not C++ style.

  13. #13
    Join Date
    Jan 2004
    Posts
    20

    Thumbs down

    Originally posted by kasracer
    Because the C++ standard says NOT to. A function requiring no arguements (you don't want to send any to main) does not need to be sent void. That is C, not C++ style.
    you are mistaken. void is a perfectly legal C++ function argument - I dare you to show me the exact paragraph in the standard that says different. however, if you DO look at the standard, you'll see something like the example in 8.3.5.1, saying that

    int f();
    means
    int f(void); in C++
    and
    int f(unknown) in C

    to come back to the original thread question, cout is not a part of STL - and to use C++ standard objects you need to link against the implementing library (libstdc++.* in this case). g++ automatically does this for you, while the generic frontend gcc does not and requires -lstdc++

    finally, you DO want sometimes arguments to main() - ever heard of:

    int main(int argc, char** argv)

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: STL and Linux

    Originally posted by KnNeeded
    I tried to use the iostream template class in the STL library
    As abc_coder points out, iostreams is not part and has never been part of STL. The iostreams library has existed since the first C++ compilers existed, separate and apart from STL. Go to the SGI web site and look in the STL section -- you will find nothing there about iostreams. Get a book on just STL -- again you will find nothing on iostreams (except maybe an example using cout).

    I know it sounds like a small thing to be concerned about, but I have seen programmers waste valuable time looking for information on iostreams, and where do they look? They look in the STL references, thereby not finding anything, wasting their time.

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Originally posted by abc_coder
    you are mistaken. void is a perfectly legal C++ function argument
    So is many other things in C but that doesn't mean you should do it.
    Originally posted by abc_coder
    I dare you to show me the exact paragraph in the standard that says different. however, if you DO look at the standard, you'll see something like the example in 8.3.5.1, saying that

    int f();
    means
    int f(void); in C++
    You do realize that proves my point, right? It shows that f() means the samething as f(void).

    Besides, when I did a search for 8.3.5.1 I didn't find ANYTHING, but in the standard in 8.3.5 it mentions
    restricts the use of void as parameter type
    I don't even know why you would top this thread now, it's a bit late.

Page 1 of 2 12 LastLast

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