0

I have never been good at reading and understanding C & C++ Library documentation, for some reason. It's drives me insane. If I see a working sample then I'm good for most other things.

I have installed libsmbios-dev and libsmbios-doc on my ubuntu based machine. The Library docs are located at /usr/share/doc/libsmbios-doc/doxygen/libsmbios_c

Can anyone provide a working example of pulling the service tag number on a dell machine using libsmbios?

I've search and I can't seem to find what i'm looking for.

Thank you

Steven Lutz
  • 467
  • 1
  • 6
  • 16

2 Answers2

0

Could this function be the one you're looking for?

char *sysinfo_get_service_tag();

Defined in service_tag.c, declared in system_info.h. I am unable to test this, but you would presumably include this file in your code.

#include <smbios_c/system_info.h>
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
  • That makes sense! How did you find it? – Steven Lutz May 10 '20 at 04:36
  • Just searched the library on GitHub and looked for a file with 'service tag' in the name. – Chris Loonam May 10 '20 at 04:36
  • but being that I installed the -dev package on my machine.. it seems that I wouldn't service_tag.c right? and if so, where is it so I can include it somehow? – Steven Lutz May 10 '20 at 04:39
  • I do have system_info.h and can include that. but I don't seem to have service_tag.c anywhere. I'm guessing you're saying to reuse code from service_tag.c in my prog? Asking as many questions as I can before i start chasing my tail for no reason. I appreciate the help. – Steven Lutz May 10 '20 at 06:25
  • You don’t need the C file, that was just for information. You need to include that file in your code, and then add -lsmbios when compiling to link the library (or -lsmbios_c) – Chris Loonam May 10 '20 at 15:41
  • Why do I need to use the -lsmbios during compile if I'm already referencing ath header file? – Steven Lutz May 11 '20 at 05:56
  • The header gets you the function declaration, which is needed at compile time. However, the definition (the compiled function in the C file I mentioned in the answer) is located in libsmbios, a dynamic library. By specifying -lsmbios, the linker is able to find the actual compiled code for that function. – Chris Loonam May 11 '20 at 05:58
  • So it's not actually compiling the header file I'm referencing? but rather referring to it for my programs compilation and dynamically linking the existing compiled library? – Steven Lutz May 11 '20 at 06:25
  • Essentially, yes. The header file with the declaration tells the compiler nothing more than that the function exists with the given signature (returns `char*`, takes no args, name). The actual code that is executed when you call it is stored in the dynamically linked library (libsmbios). – Chris Loonam May 11 '20 at 06:38
  • That makes sense. Can it be linked statically for portability without much trouble? – Steven Lutz May 11 '20 at 06:40
  • That probably depends on how the library was compiled. You'll likely need a statically-compiled version of the library (probably having extension `.a`). If you can't find one, the GitHub link in the answer will allow you to compile the source directly. – Chris Loonam May 11 '20 at 06:41
  • For more info on that, look here. (https://stackoverflow.com/questions/725472/static-link-of-shared-library-function-in-gcc) – Chris Loonam May 11 '20 at 06:42
0

at the top of your code:

#include <smbios_c/system_info.h>

when you want to obtain the service tag, in your program.

just call the function, from the library, that performs the desired operation. I.E.

sysinfo_get_dell_system_id();

which returns an int that is the system ID

There is no need to have the source code, as the executable function is in the library. libsmbios-def, which you will need to include in your link step.

user3629249
  • 16,402
  • 1
  • 16
  • 17