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

Thread: Linking stage

  1. #1
    Join Date
    May 2018

    Linking stage

    I'm learning C++ using Linux text console (no gui) by g++ compiler, I created wrote the following files:


    I run command g++ help.cpp main.cpp and ./a.out file is created so I run it to test software.
    I'd like linking stage because in previous command no library is specified so I'm thinking default libraries are added.
    I'm using iostream and cstring libraries.
    My study work says it's necessary to add at g++ -l<library> but I ask help to experts

  2. #2
    Join Date
    Jan 2006

    Re: Linking stage

    Refer to the GCC manual on Compiling C++ Programs:
    C++ source files conventionally use one of the suffixes ‘.C’, ‘.cc’, ‘.cpp’, ‘.CPP’, ‘.c++’, ‘.cp’, or ‘.cxx’; C++ header files often use ‘.hh’, ‘.hpp’, ‘.H’, or (for shared template code) ‘.tcc’; and preprocessed C++ files use the suffix ‘.ii’. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).

    However, the use of gcc does not add the C++ library. g++ is a program that calls GCC and automatically specifies linking against the C++ library. It treats ‘.c’, ‘.h’ and ‘.i’ files as C++ source files instead of C source files unless -x is used. This program is also useful when precompiling a C header file with a ‘.h’ extension for use in C++ compilations. On many systems, g++ is also installed with the name c++.
    As such, you did not need to explicitly link against the C++ standard library despite using <iosteam> and <cstring> because you compiled with g++ instead of gcc.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)