想在UBUNTU伙伴中连接POWERUSB

时间:2016-04-12 02:40:07

标签: c++ ubuntu shared-libraries raspberry-pi2

对于我的研究原型,我需要连接powerusb(http://www.pwrusb.com/)智能开关并与我的Raspberry Pi 2 B进行通信.Linux开发人员文件在powerusb网站上提供,并在UBUNTU上进行测试。我也在使用Ubuntu MATE。这是我的示例代码:

#include <dlfcn.h>  
#include <stdio.h>
#include "powerusb.h"
#include <stdlib.h>

    int main (void)
    {
        void *sharedLibraryHandle;
        sharedLibraryHandle = dlopen ("/usr/lib/libpowerusb.so", RTLD_LAZY);
        if (!sharedLibraryHandle) 
        {
            fprintf(stderr,"%s\n", dlerror());
            exit(1);
        }else
        {
            printf("SUCCESS");
            }
        int (*SetPortPowerUSB_Address)(int, int, int); 
        //            - The function can be called by the following commands 
        SetPortPowerUSB_Address = (int (*)(int, int, int))dlsym(sharedLibraryHandle, "SetPortPowerUSB");
        (*SetPortPowerUSB_Address)(1, -1, -1);
                      //- The above code sets the powerusb port states to port1 = on, port2 = off and port3 = off.
    dlclose(sharedLibraryHandle);
    exit(3);
    }

COMPILE没有错误,我在构建时使用 -ldl 命令。但是在编译之后我运行程序时显示以下结果:

/usr/lib/libpowerusb.so: cannot open shared object file: No such file or directory


------------------
(program exited with code: 1)
Press return to continue

这意味着它无法连接到库(我猜)。如果有人有这方面的经验,请帮忙。仅供参考,我已经将库文件粘贴到那里并在那之后运行 ldconfig 。 ls -l /usr/lib/libpowerusb.so显示 -rw-r - r-- 1 root root 26046 Apr 11 20:11 /usr/lib/libpowerusb.so

感谢ADVANCE

0 个答案:

没有答案