How the C++ Linker Works
Why Stack Overflow recommends it
Stack Overflow users link it when asking about linker errors, undefined references and how separate .cpp files get combined into one program.
Recommended by 1 people across 1 different months, 2020 to 2024.
What it is
A 16-minute episode from The Cherno's C++ series that explains what the linker does after compilation. It covers resolving symbols across object files, undefined reference errors, duplicate definitions, and how static functions affect linking, with demos in Visual Studio.
What people said
Recommends Garrett · 2022-01 · Stack Overflow · on “How to create a constructor in source file C++”
I have been researching for hours. This simple task is eluding me... Any suggestions of refactoring are encouraged. I am not a C++ person obviously. I've watched all these videos but none of the demo classes have multiple fields. I certainly have not seen a source file that initializes a null array. Links: C++ - Classes - Creating Source files and Header files [LINK] Buckys C++ Programming Tutorials - 15 - Placing Classes in Separate Files [LINK] C++ Header Files* [LINK] How the C++ Linker Works [this video] Constructors in C++ [LINK] How to Write a C++ Class [LINK] Separating a C++ class into a .h and .cpp files [LINK] After a few comments I have updated the context of the question Node.h #ifnde
Cites Miervatea · 2020-06 · Stack Overflow · on “visual studio c++ does it build only files shown in the tab?”
I'm new to C++ and was following the instruction steps here [this video] The situation was I have math.cpp file where contains two functions. One of those function was already in the other cpp file in the same project so I have removed it. The build worked however, when I tried to recreate the removed cpp with the same name, it said this already exsits. In the file explorer, the file was there not deleted completely. Now I'm confused how this visual studio building works. Does it only builds the cpp files which is shown in the tab even though some files not included may exist in the same folder? I was wondering wouldn't this cause a problem in the future when you are programming and some of the f
Cites Josael Perez · 2020-09 · Stack Overflow · on “C++: How compiler and linker work when you have same function (static and non-static)?”
Let me explain what I want to understand, recently I see these videos from youtube about how the compiler and the linker work. How C++ works: [LINK] How C++ compiler works: [LINK] How C++ linker works: [this video] In those videos, it is explained what happens when you have functions with the same declaration and definition, but just have examples with static to static functions (that solves the linking error since each function is seen different) and non-static to non-static functions (which gives a linking error since the linker do not know what function are you calling). However, those videos are just extra information I will explain my doubt. Suppose we want to have to functions with the same
Cites Pavel.Zh · 2021-06 · Stack Overflow · on “CMake: How can I check if a STATIC library has been compiled with -stdlib=libc++?”
There is no need to check this for static libraries. Static libraries are just archives with object files and they have no runtime dependencies. They are linked directly to your final binary file. You should read more about how linker works: Stack overslow answer [LINK] Wikipedia [LINK] [this video] If you compile your final binary without libc++ and do not have any "undefined reference" error - everything is fine. Otherwise if the undefined symbols are functions from lib++, your static libraries were compiled with libc++ support. The only way you can check symbole before linkage stage is checks symbols, which static libraries contain. See this answer about how to do this [LINK]
Cites Adeeb · 2022-02 · Stack Overflow · on “Linker Error with undefined reference to a function”
I am new to Stack OF and C++. And I am following a tutorial by The Cherno [this video] wherein at 7:00 he is explaining how the linker would not try search for a function "Log" if the it is present in an unused static function. Which makes sense! However upon me trying it. I don't get the same result and I do get a linker error. Here is my code: main.cpp #include <iostream> void Logger(const char*); static int Multiplied(int a, int b, int c){ Logger("Hello"); return a * b; } int main(){ //Logger("Hello World from Log function \n"); //std::cout << Multiplied(3,4) << std::endl; } my source directory only has main.cpp ls -lrth src total 4,0K -rw-rw-r-- 1 ubuntu18 ubuntu18 232 Feb 22 04:19 Main.cpp T
Cites Pranjal · 2022-05 · Stack Overflow · on “Generate preprocesed file ( .i ) in code blocks”
I am following The Cherno C++ series [this video] and in this video he is talking about generating .i files. I am an Ubuntu [20.04] user and am making my projects on Code::Blocks. Does any one know how to generate .i files in Code::Blocks?
Cites Franz Kafka · 2024-10 · Stack Overflow · on “The function that has not been called still reports an error in the link stage,”
Well, I don't know. Those teaching videos were 7 years ago. Maybe c++ changed? I found his original words.https: [this video]