问题:
开发环境at91sam9260,原先为了赶开发进度,总是使用静态连接来生成可执行程序;
现在,要改成使用共享库的方式运行可执行程序;
解决办法:
1. 编译过程中去掉-static选项;
CC = arm-linux-g++
CC-EW = arm-linux-gcc
CCFLAGS = -g3 -Wall -o0 -I../../../tools/eldk42/arm/usr/include/ -I../../../tools/eldk42/arm/usr/include/C++/4.2.2/ -I./energywise/include/
CCFLAGS-EW = -g3 -Wall -o0 -I../../../tools/eldk42/arm/usr/include/ -I../../../tools/eldk42/arm/usr/include/C++/4.2.2/ -I./energywise/include/ -I./energywise/ref_agent/ -I./energywise/src -I\openssl -I.
LDFLAGS = -L../../../tools/lib/ -lpthread -lCiscoEnergyWiseSdk
RM = rm -f
SOURCES_CPP = main.cpp model.cpp modelc.cpp IniFile.cpp \
ClientSocket.cpp Thread.cpp SensorReader.cpp \
LcdWriter.cpp Monitor.cpp Helper.cpp Mutex.cpp serial.cpp
OBJECTS = $(SOURCES_CPP:%.cpp=%.o) RefAgent.o
all: pdu
.PHONY : all
%.o: %.cpp
$(CC) $(CCFLAGS) -c $< -o $@
RefAgent.o: ./energywise/ref_agent/RefAgent.c
$(CC-EW) $(CCFLAGS-EW) -c ./energywise/ref_agent/RefAgent.c -o RefAgent.o
pdu : $(OBJECTS)
$(CC) $(LDFLAGS) -static -o pdu $(OBJECTS)
把最后一行中的-static去掉,变成
CC = arm-linux-g++
CC-EW = arm-linux-gcc
CCFLAGS = -g3 -Wall -o0 -I../../../tools/eldk42/arm/usr/include/ -I../../../tools/eldk42/arm/usr/include/C++/4.2.2/ -I./energywise/include/
CCFLAGS-EW = -g3 -Wall -o0 -I../../../tools/eldk42/arm/usr/include/ -I../../../tools/eldk42/arm/usr/include/C++/4.2.2/ -I./energywise/include/ -I./energywise/ref_agent/ -I./energywise/src -I\openssl -I.
LDFLAGS = -L../../../tools/lib/ -lpthread -lCiscoEnergyWiseSdk
RM = rm -f
SOURCES_CPP = main.cpp model.cpp modelc.cpp IniFile.cpp \
ClientSocket.cpp Thread.cpp SensorReader.cpp \
LcdWriter.cpp Monitor.cpp Helper.cpp Mutex.cpp serial.cpp
OBJECTS = $(SOURCES_CPP:%.cpp=%.o) RefAgent.o
all: pdu
.PHONY : all
%.o: %.cpp
$(CC) $(CCFLAGS) -c $< -o $@
RefAgent.o: ./energywise/ref_agent/RefAgent.c
$(CC-EW) $(CCFLAGS-EW) -c ./energywise/ref_agent/RefAgent.c -o RefAgent.o
pdu : $(OBJECTS)
$(CC) $(LDFLAGS) -o pdu $(OBJECTS)
在本地库目录../../../../tools/lib中,既有静态库文件*.a供静态链接使用,又有*.so和其符号链接供动态链接使用;
2. 将动态生成的pdu下载到目标板中;
# cd /usr/local
# tftp -r pdu -g 192.168.37.200
使用命令
# LD_TRACE_LOADED_OBJECTS=1 ./pdu
来查看pdu所依赖的库文件
[root@34BCA6000001: local]# LD_TRACE_LOADED_OBJECTS=1 ./pdu
libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
libCiscoEnergyWiseSdk.so.1 => not found
libstdc++.so.6 => /lib/libstdc++.so.6 (0x40043000)
libm.so.6 => /lib/libm.so.6 (0x40120000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x401cd000)
libc.so.6 => /lib/libc.so.6 (0x401e0000)
/lib/ld-linux.so.3 (0x40000000)
提示缺少libCiscoEnergyWiseSdk.so.1,将libCiscoEnergyWiseSdk.so下载到目标板的/lib目录,再次查询所依赖的库文件
[root@34BCA6000001: local]# LD_TRACE_LOADED_OBJECTS=1 ./pdu
libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
libCiscoEnergyWiseSdk.so.1 => /lib/libCiscoEnergyWiseSdk.so.1 (0x40043000)
libstdc++.so.6 => /lib/libstdc++.so.6 (0x40091000)
libm.so.6 => /lib/libm.so.6 (0x4016e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4021b000)
libc.so.6 => /lib/libc.so.6 (0x4022e000)
/lib/ld-linux.so.3 (0x40000000)
libssl.so.6 => not found
libcrypto.so.6 => not found
libuuid.so.1 => /lib/libuuid.so.1 (0x4034c000)
提示缺少libssl.so.6、libcrypto.so.6,将这两个库文件下载到目标板中,再查
[root@34BCA6000001: local]# LD_TRACE_LOADED_OBJECTS=1 ./pdu
libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
libCiscoEnergyWiseSdk.so.1 => /lib/libCiscoEnergyWiseSdk.so.1 (0x40043000)
libstdc++.so.6 => /lib/libstdc++.so.6 (0x40091000)
libm.so.6 => /lib/libm.so.6 (0x4016e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4021b000)
libc.so.6 => /lib/libc.so.6 (0x4022e000)
/lib/ld-linux.so.3 (0x40000000)
libssl.so.6 => /lib/libssl.so.6 (0x4034c000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x4038e000)
libuuid.so.1 => /lib/libuuid.so.1 (0x40499000)
libgssapi_krb5.so.2 => not found
libkrb5.so.3 => not found
libcom_err.so.2 => /lib/libcom_err.so.2 (0x404a4000)
libk5crypto.so.3 => not found
libresolv.so.2 => /lib/libresolv.so.2 (0x404ae000)
libdl.so.2 => /lib/libdl.so.2 (0x404c8000)
libz.so.1 => /lib/libz.so.1 (0x404d3000)
提示缺少libgssapi_krb5.so.2、libkrb5.so.3和libk5crypto.so.3;将这三个库文件下载到目标板中,再查
[root@34BCA6000001: local]# LD_TRACE_LOADED_OBJECTS=1 ./pdu
libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
libCiscoEnergyWiseSdk.so.1 => /lib/libCiscoEnergyWiseSdk.so.1 (0x40043000)
libstdc++.so.6 => /lib/libstdc++.so.6 (0x40091000)
libm.so.6 => /lib/libm.so.6 (0x4016e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4021b000)
libc.so.6 => /lib/libc.so.6 (0x4022e000)
/lib/ld-linux.so.3 (0x40000000)
libssl.so.6 => /lib/libssl.so.6 (0x4034c000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x4038e000)
libuuid.so.1 => /lib/libuuid.so.1 (0x40499000)
libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x404a4000)
libkrb5.so.3 => /lib/libkrb5.so.3 (0x404d2000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x4054d000)
libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x40557000)
libresolv.so.2 => /lib/libresolv.so.2 (0x40583000)
libdl.so.2 => /lib/libdl.so.2 (0x4059d000)
libz.so.1 => /lib/libz.so.1 (0x405a8000)
libkrb5support.so.0 => not found
libkrb5support.so.0 => not found
libkrb5support.so.0 => not found
提示缺少libkrb5suport.so.0,将该库文件下载到目标板中,再查
[root@34BCA6000001: local]# LD_TRACE_LOADED_OBJECTS=1 ./pdu
libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
libCiscoEnergyWiseSdk.so.1 => /lib/libCiscoEnergyWiseSdk.so.1 (0x40043000)
libstdc++.so.6 => /lib/libstdc++.so.6 (0x40091000)
libm.so.6 => /lib/libm.so.6 (0x4016e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4021b000)
libc.so.6 => /lib/libc.so.6 (0x4022e000)
/lib/ld-linux.so.3 (0x40000000)
libssl.so.6 => /lib/libssl.so.6 (0x4034c000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x4038e000)
libuuid.so.1 => /lib/libuuid.so.1 (0x40499000)
libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x404a4000)
libkrb5.so.3 => /lib/libkrb5.so.3 (0x404d2000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x4054d000)
libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x40557000)
libresolv.so.2 => /lib/libresolv.so.2 (0x40583000)
libdl.so.2 => /lib/libdl.so.2 (0x4059d000)
libz.so.1 => /lib/libz.so.1 (0x405a8000)
libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x405c1000)
可以看到不再缺少库文件了。
运行pdu程序,熟悉的界面又出来了。
问题解决。