[Day 16] - Static and Dynamic Libraries (ar, objdump, ld, ldd) - Crash Course in C Programming

  Рет қаралды 10,410

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 43
@timesink6325
@timesink6325 4 ай бұрын
As a beginner to c, this is my sum up.Hope to help someone like me:) 1.complie multiple c files under the src directory: gcc ./src/main.c ./src/mymath.c ./src/mymath2.c -I./include -o prog -> prog 2.complie all c files under the src directory: gcc ./src/*.c -I./include -o prog -> prog 3.creat static library: gcc -c ./src/main.c -I./include -> main.o 4.using the archive tool: ar rcs mymath.a mymath.o mymath2.o -> mymath.a 5.embed the static library into the final executable: gcc main.o mymath.o mymath2.o -o prog -> prog 6.creat dynamic library(shared library) : gcc -fPIC -shared ./src/mymath.c -I./include -o libmymath.so -> libmymath.so 7.linked with the dynamic library : gcc ./src/main.c -I./include -o hello -lmymath -lmymath2 -L./ -> hello 8.run the hello program: LD_LIBRARY_PATH="./" ./hello 9.the difference between static library and dynamic library: the code of the static library gets embeded into the final executable at compile time, but the code of the dynamic library does not get embeded into the executable.instead, the linking happens at runtime, this requires the dynamic library to be present on the system at runtime.
@MikeShah
@MikeShah 4 ай бұрын
Looks like a nice summary -- well done! (Will pin for a bit)
@timesink6325
@timesink6325 4 ай бұрын
@@MikeShahThanks mike! i enjoy your lessons very much.
@MikeShah
@MikeShah 4 ай бұрын
@@timesink6325 cheers!
@richardkombo5537
@richardkombo5537 Жыл бұрын
The fact that you experience the errors and solve them make the lesson worthwhile so we are able to watch out for the same errors in the future......Your lessons are really appreciated
@MikeShah
@MikeShah Жыл бұрын
Cheers, thank you for the kind words :)
@Southpaw101
@Southpaw101 Жыл бұрын
This is exactly what I was looking for. Whole day I have been working on the c++ series and luckily found this. Thanks.
@MikeShah
@MikeShah Жыл бұрын
Cheers! Happy to help!
@dd-iu6iy
@dd-iu6iy 8 ай бұрын
Great lecture, you gradually move from beginner to advanced level concepts. Great teaching skills sir.
@MikeShah
@MikeShah 8 ай бұрын
Thank you for the kind words!
@MichaelOzoro
@MichaelOzoro Жыл бұрын
Wow! Thanks Mike (my namesake) This is really nice, I enjoyed the lesson, I like the way you simplify and break down the compilation process, thumb up to you!!!
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@behrampatel4872
@behrampatel4872 2 ай бұрын
Such a fantastic tutorial on fundamentals. I'm learning openCV using c++ and need to brush up on my basics (because of all the header & lib includes to get started). This video is just perfect. Hope you do windows as well. Cheers, b
@MikeShah
@MikeShah 2 ай бұрын
@@behrampatel4872 cheers!
@behrampatel4872
@behrampatel4872 2 ай бұрын
@@MikeShah I have one request mike. I'm trying to emulate this on windows visual studio using the developer command prompt. I'm able to get a basic hello world compiled but when I follow your tutorial on including other directories it gives me linker errors. KZbin only shows the beginning step of getting a hello world working and nothing beyond that. Can you point to a tutorial on how to go beyond that using the Developer command prompt please ? I'm resisting the urge to download gcc and follow along and call it a day. Thanks a ton.
@MikeShah
@MikeShah 2 ай бұрын
@@behrampatel4872 Many folks use VSCode which has a command prompt (usually folks do use gcc or mingw (windows port of gcc) to achieve this). I believe Visual Studio has the ability to run msvc in a prompt somewhere, I just have not used it (i.e. when I use Visual Studio, I use the full IDE and just hit F5 or the build&run buttons from the GUI)
@behrampatel4872
@behrampatel4872 2 ай бұрын
​@@MikeShah No probs. Its called the Developer Command Prompt. There is documentation on it on the windows website but it's written for people already in the know or to intentionally turn people off :P. I'm going with g++ and getting in some practice based on the exercises above. Happy to report that things work like a charm. I'm not able to replicate the shared object workflow on windows though. Im guessing because windows would require DLL'S instead of SO's. So the hunt begins on how to do that using g++. Cheers and you're the best... b
@antenehtaye4973
@antenehtaye4973 Жыл бұрын
Thank you Mike, its a great demo hope you can pace down a lil bit i found it hard to keep up.😊
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@felipealemanha
@felipealemanha Жыл бұрын
Hey, man! Your contents is helping me a lot. Hugs from Brazil!
@MikeShah
@MikeShah Жыл бұрын
Cheers! Happy to hear that!
@rzwnhmd
@rzwnhmd Жыл бұрын
this topic was just amazing. Now I know what its meant when they say that "GCC" does some magic into compiling process. Looking forward to learn more about this topic
@MikeShah
@MikeShah Жыл бұрын
Cheers, thank you for the kind words!
@Kirfx
@Kirfx 11 ай бұрын
Thank you so much!
@MikeShah
@MikeShah 11 ай бұрын
Cheers!
@joshbrice5678
@joshbrice5678 2 жыл бұрын
Thank you Mike. 😄
@MikeShah
@MikeShah 2 жыл бұрын
You are most welcome Brice!
@michaeljumah6960
@michaeljumah6960 Жыл бұрын
thanks so much....this is a lifesaver
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@ugochukwuokpoko7593
@ugochukwuokpoko7593 10 ай бұрын
Awesome piece. Can one get the "tree" source file you used during the lecture?
@MikeShah
@MikeShah 10 ай бұрын
Cheers! tree is installed with 'sudo apt-get install tree'
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
Hallo Mike, Thumb up for the videos and this topic. I will wash it later.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers Blaiso!
@GaryChike
@GaryChike 2 жыл бұрын
The video does need sanitizing 😅
@tsarprince
@tsarprince 5 ай бұрын
Damn so informative!
@MikeShah
@MikeShah 5 ай бұрын
Cheers, happy to hear that!
@aghiadalzein3069
@aghiadalzein3069 8 ай бұрын
Thanks ,but this lesson was the hardest for me.
@MikeShah
@MikeShah 8 ай бұрын
Cheers -- there's quite a bit of new material here indeed!
@Random-sm5gi
@Random-sm5gi Жыл бұрын
Can you please talk about dlopen u mentioned at the end of the lesson? Thank you so much bro it was very helpful.
@MikeShah
@MikeShah Жыл бұрын
In the planning stages -- probably have something out in the next month or two on dlopen if not sooner.
@MuhammetUçan-y7c
@MuhammetUçan-y7c 8 ай бұрын
Hi, I'd like to ask a question if you dont mind. When you wrote mymath.c you included mymath.h header to it, but when I tried It actually perfectly work without including mymath.h to mymath.c file. I guess we don't need to add that but since you added I wonder if there is a special reason for that.
@MikeShah
@MikeShah 8 ай бұрын
Functions also provide the declaration with the definition. However, when you need to use the file more than once it could cause problems in compilation if you don't have the header
@MuhammetUçan-y7c
@MuhammetUçan-y7c 8 ай бұрын
@@MikeShah Thank you for your answer.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 12 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 4,9 МЛН
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 7 МЛН
Static and Dynamic Linking on Linux with gcc
27:09
embeddedarmdev
Рет қаралды 47 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 325 М.
Code Libraries - Computerphile
8:45
Computerphile
Рет қаралды 93 М.
Static vs. Shared Libraries
11:00
Dave Xiang
Рет қаралды 65 М.
Using Libraries in C++ (Static Linking)
18:43
The Cherno
Рет қаралды 446 М.
Creating and Linking Shared Libraries on Linux with gcc
29:12
embeddedarmdev
Рет қаралды 22 М.
you need to stop using print debugging (do THIS instead)
7:07
Low Level
Рет қаралды 453 М.
Write Better Code!  |  How to Create Shared Libraries in C/C++
13:59
The intro to Docker I wish I had when I started
18:27
typecraft
Рет қаралды 239 М.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 12 МЛН