我正在尝试为我的手臂目标制作一个小型应用程序。我已经在linux下的eclipse中设置了工具链。现在我正在尝试构建库。
这是我的库头文件 led.h:
#ifndef LED_H_
#define LED_H_
extern char ledon(char lednum);
extern char ledoff(char lednum);
#endif /* LED_H_ */
和我的 c 文件 led.c :
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <led.h>
int fd = 0;
char ledon(char lednum)
{
switch(lednum)
{
case 0 :fd = open("/sys/class/leds/beaglebone::usr0/brightness", O_WRONLY);
break;
case 1 :fd = open("/sys/class/leds/beaglebone::usr1/brightness", O_WRONLY);
break;
case 2 :fd = open("/sys/class/leds/beaglebone::usr2/brightness", O_WRONLY);
break;
case 3 :fd = open("/sys/class/leds/beaglebone::usr3/brightness", O_WRONLY);
break;
}
if (fd>0)
{
write(fd,"1",sizeof(char));
close(fd);
return 1;
}
else
{
printf("Message form library function\n Error reading the LED %d",lednum);
return 0;
}
}
char ledoff(char lednum)
{
switch(lednum)
{
case 0 :fd = open("/sys/class/leds/beaglebone::usr0/brightness", O_WRONLY);
break;
case 1 :fd = open("/sys/class/leds/beaglebone::usr1/brightness", O_WRONLY);
break;
case 2 :fd = open("/sys/class/leds/beaglebone::usr2/brightness", O_WRONLY);
break;
case 3 :fd = open("/sys/class/leds/beaglebone::usr3/brightness", O_WRONLY);
break;
}
if (fd>0)
{
write(fd,"0",sizeof(char));
close(fd);
return 1;
}
else
{
printf("Message form library function\n Error reading the LED %d",lednum);
return 0;
}
}
编译上面我得到led.h和libled.so。
现在我在另一个项目中创建了一个测试 c 文件 ledtest.c。
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <led.h>
int main(void) {
while(1)
{
ledon(2);
sleep(1);
ledoff(2);
sleep(1);
}
return EXIT_SUCCESS;
}
我创建了两个文件夹“include”,其中包含 led.h 和“lib”,其中包含 libled.so。
现在当我编译 ledtest.ci 得到以下错误
make all
Building target: ledtest
Invoking: GCC C Linker
arm-linux-gnueabi-gcc -L/usr/arm-linux-gnueabi/lib -L/home/sanatan/Coustom/lib -o
"ledtest" ./src/ledtest.o
./src/ledtest.o: In function `main':
ledtest.c:(.text.startup+0x4): undefined reference to `ledon'
ledtest.c:(.text.startup+0x10): undefined reference to `ledoff'
collect2: ld returned 1 exit status
make: *** [ledtest] Error 1
但是如果我在库中添加 libled.so :
我收到以下错误:
**** Build of configuration Release for project ledtest ****
make all
Building file: ../src/ledtest.c
Invoking: GCC C Compiler
arm-linux-gnueabi-gcc -I/home/sanatan/Coustom/include -I/usr/arm-linux-
gnueabi/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ledtest.d" -
MT"src/ledtest.d" -o "src/ledtest.o" "../src/ledtest.c"
Finished building: ../src/ledtest.c
Building target: ledtest
Invoking: GCC C Linker
arm-linux-gnueabi-gcc -L/usr/arm-linux-gnueabi/lib -L/home/sanatan/Coustom/lib -o
"ledtest" ./src/ledtest.o -l/home/sanatan/Coustom/lib/libled.so
/usr/lib/gcc/arm-linux-gnueabi/4.6.1/../../../../arm-linux-gnueabi/bin/ld: cannot
find -l/home/sanatan/Coustom/lib/libled.so
collect2: ld returned 1 exit status
make: *** [ledtest] Error 1
**** Build Finished ****
但我确信文件在那里:
root@ubuntu:/home/sanatan/Coustom/lib# ls
led.o libled.so
有人可以在这里帮助我吗,我不知道该怎么办。相信我,我做了功课.. :)
提前致谢。
萨纳坦