Here is something I would like to point out that I did not really mention in the video. In this video, I only created a static library, I did not create a corresponding shared library (.so) for this library. As a result of this, the only possibility for linking the code from libmath is statically. The default behavior for the linker is to link dynamically and will therefore look for the shared library first, libmath.so in this example. Since the shared library did not exist, it then looked for the static version (libmath.a) and since it found it, it compiled the libmath code into the binary statically. Now, if I had created both a static (libmath.a) and shared library (libmath.so), then the default would have been to compile it dynamically. It would have looked for and found the libmath.so and then that code would have been compiled in dynamically. In this case, when both static/dynamic libraries exist, in order to force it to go static, you have to include the 'static' keyword. This will look only for the libmath.a and will only be successful if it exists. Incidentally, you can use the -Wl option to pass the -Bstatic and -Bdynamic options to the linker to toggle back and forth between static and dynamic linking. So, if you have the following gcc command: gcc test.c -o test -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar All code from libfoo would be compiled statically and all code from libbar would be dynamically linked. There would need to be a libfoo.a and a libbar.so for this to be successful. Also note that any libc code would be compiled based on the final -WL, -Boption that is on the command line. If we do this gcc test.c -o test -Wl,-Bstatic -lfoo Then both libfoo and libc would be compiled in statically, so make sure to add the final -Wl,-Bdynamic option to switch it back to the default.
@binwei28293 жыл бұрын
Really great video. It shows a step by step example to let you know how to create your own one. Thanks!
@adampassaretti91492 жыл бұрын
thank you so much bro
@foxOneRides Жыл бұрын
made it very easy to understand. a hidden gem indeed.
@Random-sm5gi6 ай бұрын
Very informative. Thanks boss.
@zvxcvxcz Жыл бұрын
Edit: Sorry, -Wl, was explained incorrectly before with an incorrect example as well. Just an aside, there are some libraries that are not easy or are not possible or practical to compile statically. For example, you can't really include -lGL statically. To tell gcc/g++ to do some libs statically but not others, you can '-Wl, -Bstatic' and '-Wl, -Bdynamic' before the respective libraries. Like this: g++ yourcode.cpp -I someinclude -I someotherinclude -L someliblocation -L someotherliblocation -Wl,-Bstatic -lsomestaticlib -Wl, -Bdynamic -lsomelibnotstatic Some libC functions are problematic, e.g. dlopen(), if I recall is will static compile, but it still won't work if the glibc version doesn't match. Network code is also frequently difficult to get a static compilation for, e.g. libcurl. I was trying to compile htslib myself statically and having problems, but it turns out it's fine as long as you don't need to load/write files over the network (just leave out libcurl). I think they actually do build the static .a file by default (without libcurl), but they say nothing about it in the build documentation. A further aside (I'm no longer on topic so this is just for information for people, it isn't meant as a critique), the old rand() functions are pretty bad. If random numbers are even remotely important to one's application, then they should at a minimum use something like Mersenne Twister, but I would actually prefer PCG. There should be C libraries available for both of these and in newer versions of C++ Mersenne Twister is available in the standard library (but I believe normal rand still works the old way for compatibility purposes, need to call up the RNG the new way). Nice clear video though. On the side I see you have some other videos on the topic, longer as well, perhaps you get into some of these weeds there, I just haven't watched yet.
@nighttime9539 Жыл бұрын
What a bunch of random info. It's good to know but I dont see how it relates to the video.
@John223 Жыл бұрын
Very useful. Thank you ❤
@gattomiaomiao9634 Жыл бұрын
I love your way of teaching, theory plus practical demonstrations are great
@cybernit33 ай бұрын
Thanks embeddeddarmdev. I tested it out and worked fine.
@TheGokhansimsek353 жыл бұрын
Super useful. Thx a lot!!
@ratfuk9340 Жыл бұрын
Thanks
@voidlt3 жыл бұрын
Thank you so much for this video, it helped a lot.
@greydogyoutube7 ай бұрын
Finally! Thnaks a lot man!
@mateomerino57923 жыл бұрын
thank you so much, this video help me a lot. i can advance on a homework of my career! greetings from Argentina, im really grateful.
@multivalfran2 жыл бұрын
GREAT video. I'm trully amazed
@masterbeater88443 жыл бұрын
this was great man, keep it up although it wouldn't hurt if you go a bit deeper on some of the terms you used....like what non-position-inependent means and why its needed and....... Beginners like me freeze when we hear big terminologies ;)
@nighttime9539 Жыл бұрын
Great tutorial.
@embeddedarmdev Жыл бұрын
Thank you!
@aFausify3 жыл бұрын
Big thanks man. You're a gem. Great video!
@akshaykumar71523 жыл бұрын
Thanks a lot for this video. I've found a surprising lack of content on C/C++ libraries
@MrCrazyDuck472 жыл бұрын
Thanks, very well explained. It would be also nice, if compilation with Makefile would be explained as well
@embeddedarmdev2 жыл бұрын
That's a good idea for a topic. I will add it to my list.
@splattab2 жыл бұрын
This tutorial was very helpful thank you
@leninchakravarthy14262 жыл бұрын
I really appreciate your work. I learned lot more in your tutorial than I searched online for 1 week. I suggest you make a udemy course on complete practical detailed GCC course
@embeddedarmdev2 жыл бұрын
Thank you.
@stefanklaus64412 жыл бұрын
@@embeddedarmdev Do you have a udemy course? I'd definitely recommend it!
@embeddedarmdev2 жыл бұрын
@@stefanklaus6441 I do not have a Udemy course. I had considered developing one, but I don't think I have enough content at this time to make a quality course. I also like the idea of people having free access to tutorials.
@nighttime9539 Жыл бұрын
@@embeddedarmdev youtube tutorials is a wonder of modern age. Thanks to authors like you.
@nikudayo79272 жыл бұрын
Thanks! This is a really informative tutorial :D
@embeddedarmdev2 жыл бұрын
Thank you!
@sulayenhanglimboo51102 жыл бұрын
Very helpful, thank you.
@youchialiu259911 ай бұрын
It really helps🥹🥹🥹🥹🥹
@xelad33623 жыл бұрын
Very informative! great work!
@lihuazhang46372 жыл бұрын
Thanks for your video, Is it possible to create static library using shared library?
@embeddedarmdev2 жыл бұрын
I'm not aware of any tools that do this. Often the creators of a library will distribute or make available both a shared library and the static one. Many of the libraries that we link into have both versions on the system. If you only have the shared library, I don't know of any way to create a static library from it.
@lihuazhang46372 жыл бұрын
@@embeddedarmdev Thanks for your quick reply.
@WaveSound1233 жыл бұрын
Thank you so much for your effort, it was very informative and concise. I have been looking for a video to explain manual linking for a while now, thank you again. Kind regards!
@embeddedarmdev2 жыл бұрын
Thank you. I'm glad you fund it useful.
@3ensy Жыл бұрын
So happy I found this vid thank you!
@embeddedarmdev Жыл бұрын
I'm glad you found it too. Thanks.
@ahcenebelhadi9552 жыл бұрын
Great video, the best explanation i found ! thanks a lot !!
@embeddedarmdev2 жыл бұрын
Thank you.
@kesc23 Жыл бұрын
Amazing content! with this i could compile only the "encode" part of webp lib with gcc (as emcc) / ar (as emar). thus, obtaining a smaller .wasm file🚀
@yousefelbaz2699 Жыл бұрын
tracing every error that appears to you and finding out its cause for the first person to deal with these programs Very great thing 👌
@Qwerty_9452 ай бұрын
Hey Sir ! what is -lmath ?
@embeddedarmdev2 ай бұрын
The -l option (lowercase L) tells gcc that we want to link to a specific library. The convention is to use the name of the library, without the 'lib' prefix. So, if we have a library called libmath, then we drop the 'lib' part of it to get just 'math'. Then we append that to the -l to get: -lmath In this video, libmath is the static library that I created in the first half of the video using the 'ar' command.
@madscientist3382 жыл бұрын
Impressive thanks!!!
@embeddedarmdev2 жыл бұрын
Thank you! I appreciate it.
@Nn-Tech2 жыл бұрын
Am getting an error after adding -L lib undefined reference to 'subNumbers'
@embeddedarmdev2 жыл бұрын
Could you paste the exact gcc command you are using to compile? It could be a few things. Are you also getting an undefined reference to addNumbers or only for subNumbers?
@Nn-Tech2 жыл бұрын
Thanks , I solved it
@henriquebernardes89132 жыл бұрын
how do you solve it? I'm getting the same error
@embeddedarmdev2 жыл бұрын
I can try to help you solve it. Just need to know a bit more. Can you paste the exact gcc command you are using? And also let me know if you see the error for both addNumbers and subNumbers
@henriquebernardes89132 жыл бұрын
@@embeddedarmdev actually my Header is show me an error flag. my gcc command: gcc main.c -lmath -o main -I include -L lib. and yes, both functions are getting wrong.
@nilanjanmukhopadhyay83692 жыл бұрын
Great video! Kudos.
@embeddedarmdev2 жыл бұрын
Thanks!
@nilanjanmukhopadhyay83692 жыл бұрын
@@embeddedarmdev Are you still around? I thought you stopped making videos after a few. If that was the case I think you should start again. The way you explain things is really effective!
@embeddedarmdev2 жыл бұрын
I'm still around, I just haven't made any videos for awhile. I do them in my spare time, and recently I haven't had much of that. I do have a few more videos on my list and hope to get to them soon. Thanks for your interest!
@tomjoad69932 жыл бұрын
What if you're trying to compile on a distro and it returns an error because a shared library is in a non-standard dir but you didn't create the lib so you don't know where it is. What's the easiest way to find the lib location?
@embeddedarmdev2 жыл бұрын
On the target system, you can call ldd on the executable itself to see the name of the library it is looking for. For example: ldd program_name It will also tell you what that library name gets resolved to on your target system. Try this on some random executable like mkdir to see how it works. The only way I know of to find where a library is located is to search through directories. You could use the tool 'tree' to help. This doesn't come standard (at least on Ubuntu) so you'll have to install it. cd into the root directory (on your target system). Use the f option to list the full path to each file. You could then pipe it to grep and search for your library name. Maybe something like: tree -f | grep "library_name*.so" This might help you locate it.