-
May 31st, 2018, 12:32 AM
#1
Linking stage
I'm learning C++ using Linux text console (no gui) by g++ compiler, I created wrote the following files:
help.h
help.cpp
main.cpp
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
-
May 31st, 2018, 03:28 AM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|