Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:52:04+00:00 2026-05-31T19:52:04+00:00

This program in C runs and compiles well : #ifdef HAVE_CONFIG_H #include <config.h> #endif

  • 0

This program in C runs and compiles well :

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>

#include <atasmart.h>
int main(){
const char *device = "/dev/sda";
int ret;
 uint64_t ms;
 SkDisk *d;
         if ((ret = sk_disk_open(device, &d)) < 0) {
                        printf("Failed to open disk\n");
                        return 1;
                }





                              if ((ret = sk_disk_smart_read_data(d)) < 0) {
                                printf("Failed to read SMART data: \n");

                        }

                        if ((ret = sk_disk_smart_get_power_on(d, &ms)) < 0) {
                                printf("Failed to get power on time:\n");

                        }

                        printf("%llu\n", (unsigned long long) ms);


            return 0;

}

using:

gcc atatest.c `pkg-config --cflags --libs libatasmart` 

However while trying to create python bindings based on that program:

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>

#include <atasmart.h>

#include <Python.h>

 static PyObject *pySmart_powerOn(PyObject *self, PyObject *args)
{
    const char *device = "/dev/sda";
int ret;
 uint64_t ms;
 SkDisk *d;

    if (!PyArg_ParseTuple(args, "s", &device))
    {
        return NULL;
    }

                        if ((ret = sk_disk_smart_get_power_on(d, &ms)) < 0) {
                              return Py_BuildValue("s", "Failed to get power on time");

                        }
            return Py_BuildValue("K", (unsigned long long) ms);
}

static PyMethodDef pySmart_methods[] = {
        { "powerOn", (PyCFunction)pySmart_powerOn, METH_VARARGS, NULL },
        { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initpySmart()
{
        Py_InitModule3("pySmart", pySmart_methods, "Trial module");
}

I create a shared library using

gcc -shared -I/usr/include/python2.7 `pkg-config --cflags --libs libatasmart` atabind.c -o pySmart.so -fPIC

then I get a warning as follows :, but the file compiles

In file included from /usr/include/python2.7/Python.h:8:0,
                 from atabind.c:12:
/usr/include/python2.7/pyconfig.h:1158:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
/usr/include/features.h:214:0: note: this is the location of the previous definition

when in Python i run

import pySmart

I get

ImportError: ./pySmart.so: undefined symbol: sk_disk_smart_get_power_on

My guess is that the error is caused because I have compiled the pySmart.so shared library with incorrect flags/options.. but I’m unable to figure it out!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:52:06+00:00Added an answer on May 31, 2026 at 7:52 pm

    You need to specify linker flags (-lfoo) after your source files. That’s because of the way how linker works: when you specify a library to it, it checks the library for symbols needed so far. If no symbols needed (as if you didn’t get to any source objects yet), it just skips the library.

    Try the following commandline:

    gcc -shared -I/usr/include/python2.7 \
         `pkg-config --cflags libatasmart` \
         atabind.c \
         `pkg-config --libs libatasmart` \
         -o pySmart.so -fPIC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
I just realised that this program compiles and runs (gcc version 4.4.5 / Ubuntu):
Ok so my program compiles and runs perfectly well, but the purpose is to
This program compiles and runs on TC++ 3.0. Why don't this program compile in
I have a program which does a system call: latex somefile.latex This runs ok,
For this program #include <iostream> using std::cout; struct C { C() { cout <<
Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
I am working on this old c++ program that runs in Linux. It is
I'm writing a program for a homework assignment. The program compiles and runs, but
I am compiling this program on Windows, with gcc (MinGW) and GTK+: #include <gtk/gtk.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.