当前位置: 技术问答>linux和unix
linux 动态库调用问题
来源: 互联网 发布时间:2016-07-07
本文导语: 给个实例吧。 加入动态库后makefile文件怎么写,我现在的makefile文件如下: OBJ = main.o LINKOBJ =main.o EXEC = test CXXFLAGS = $(CXXINCS) CFLAGS = $(INCS) CC = gcc LDFLAGS = -Wl,-elf2flt .PHONY: all all-before all-after ...
给个实例吧。
加入动态库后makefile文件怎么写,我现在的makefile文件如下:
OBJ = main.o
LINKOBJ =main.o
EXEC = test
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
CC = gcc
LDFLAGS = -Wl,-elf2flt
.PHONY: all all-before all-after clean clean-custom
all: $(EXEC)
clean: clean-custom
rm -f $(OBJ) $(EXEC)
$(EXEC): $(OBJ) *.h
$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
romfs:
$(ROMFSINST) /bin/$(EXEC)
在这个基础上该如何修改?
加入动态库后makefile文件怎么写,我现在的makefile文件如下:
OBJ = main.o
LINKOBJ =main.o
EXEC = test
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
CC = gcc
LDFLAGS = -Wl,-elf2flt
.PHONY: all all-before all-after clean clean-custom
all: $(EXEC)
clean: clean-custom
rm -f $(OBJ) $(EXEC)
$(EXEC): $(OBJ) *.h
$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
romfs:
$(ROMFSINST) /bin/$(EXEC)
在这个基础上该如何修改?
|
你的动态库放在哪里的?
如果构建的时候是放在当前目录下,而且名字叫:libabc.so。那可以:
LDLIBS=-L. -labc
如果是放在系统的某个标准库目录中,就直接
LDLIBS=-labc
如果构建的时候是放在当前目录下,而且名字叫:libabc.so。那可以:
LDLIBS=-L. -labc
如果是放在系统的某个标准库目录中,就直接
LDLIBS=-labc
|
假设你有动态库文件为libmydll.so,则
DLLLIB="-L${DLL_LIB_PATH} -lmydll" //DLL_LIB_PATH为你的动态库文件所在的目录
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS) $(DLLLIB)
DLLLIB="-L${DLL_LIB_PATH} -lmydll" //DLL_LIB_PATH为你的动态库文件所在的目录
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LDLIBS) $(DLLLIB)
|
哥们 我把我工作时候的makefile给你。今天上来太晚了。嗨。。困。。调用时 dopen();
include ../stdmk.aix
VPATH=.:../../common:../../corba:../../base:../../platform
#VBROKERDIR=/opt/inprise/vbroker
OS:=$(shell uname)
ORACLE_HOME=/oracle/app/oracle/product/9.2.0
# directory that contain oratypes.h and other oci demo program header files
#-DSHOW_EXPRESSION
DEFS =-DAIX -DAIX_BITS64 -qnamemangling=v4 -q64 -bmaxdata:0x70000000 -D_REENTRANT -bloadmap -qlonglong -qlongdouble -DORACLE -D_VBROKER_ -DUSE_SOCK_AGENT -DUSE_STAT -DPTHREADS -D_AGENT_STAND_
CCFLAGS = $(CCINCLUDES) $(DEBUG)
CCINCLUDES = -I. -I$(VBROKERDIR)/include -I$(VBROKERDIR)/include/stubs
INCLUDE =$(CCINCLUDES) -I$(VBROKERDIR)/include -I../Process -I../../common -I../../corba -I../../platform -I../../base -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/rdbms/public -I$(ORACLE_HOME)/plsql/public -I$(ORACLE_HOME)/network/public
ORBCC = $(VBROKERDIR)/bin/idl2cpp
#LIBPATH = -L$(VBROKERDIR)/lib
#LIBORB =
#-lcosev_r -lcosnm_r -lvport_r -lorb_r
STDCC_LIBS = -ldl -lpthread
LDFLAGS = -L/app/cny/bin -L$(ORACLE_HOME)/lib -L$(ORACLE_HOME)/rdbms/lib -L$(CNY_HOME)/lib -ldatagent
# libraries for linking oci programs
OCISHAREDLIBS= $(ORACLE_HOME)/lib/libclntsh.a
OCISTATICLIBS= $(STATICTTLIBS) $(LLIBTHREAD)
LIBCC = -X64 -p -100 -bglink:/lib/glink64.o -bM:SRE
COMPILE_C =$(CC) -g $(DEFS) $(INCLUDE)
COMPILE_CPP =$(CPP) -g $(DEFS) $(INCLUDE)
LINK =$(CPP) -g -qmkshrobj $(LDFLAGS) $(OCISHAREDLIBS) $(LIBPATH) $(LIBORB) $(STDCC_LIBS)
# Add exe filename and source filename
TARGET1=ExhCatg.so.1 Carrier.so.1
#TARGET1= SplitAreaCode.so.1
# Add target name
all: $(TARGET1) $(depends) $(lint)
ExhCatg :ExhCatg.so.1 $(depends) $(lint)
Carrier :Carrier.so.1 $(depends) $(lint)
#C++ SOURCE FILES
SRC_CPP =CNYCommon.cpp Memory.cpp String.cpp StringArray.cpp PtrArray_t.cpp Common.cpp Oracle.cpp OracleDB.cpp
LsCorba.cpp LsCorbaAgent.cpp SocketPlus.cpp LXml.cpp Agent.cpp ServiceStat.cpp ServiceMessage.cpp
Thread.cpp Carrier.cpp ExhCatg.cpp
#C++ OBJECT FILES
OBJ_CPP = $(SRC_CPP:.cpp=.o)
#C SOURCE FILES
SRC_C =
#C++ OBJECT FILES
OBJ_C = $(SRC_C:.c=.o)
#.SUFFIXES: .o .cpp .c .idl
.SUFFIXES: .o .cpp .c
.cpp.o:
$(COMPILE_CPP) -c -o $@ $
include ../stdmk.aix
VPATH=.:../../common:../../corba:../../base:../../platform
#VBROKERDIR=/opt/inprise/vbroker
OS:=$(shell uname)
ORACLE_HOME=/oracle/app/oracle/product/9.2.0
# directory that contain oratypes.h and other oci demo program header files
#-DSHOW_EXPRESSION
DEFS =-DAIX -DAIX_BITS64 -qnamemangling=v4 -q64 -bmaxdata:0x70000000 -D_REENTRANT -bloadmap -qlonglong -qlongdouble -DORACLE -D_VBROKER_ -DUSE_SOCK_AGENT -DUSE_STAT -DPTHREADS -D_AGENT_STAND_
CCFLAGS = $(CCINCLUDES) $(DEBUG)
CCINCLUDES = -I. -I$(VBROKERDIR)/include -I$(VBROKERDIR)/include/stubs
INCLUDE =$(CCINCLUDES) -I$(VBROKERDIR)/include -I../Process -I../../common -I../../corba -I../../platform -I../../base -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/rdbms/public -I$(ORACLE_HOME)/plsql/public -I$(ORACLE_HOME)/network/public
ORBCC = $(VBROKERDIR)/bin/idl2cpp
#LIBPATH = -L$(VBROKERDIR)/lib
#LIBORB =
#-lcosev_r -lcosnm_r -lvport_r -lorb_r
STDCC_LIBS = -ldl -lpthread
LDFLAGS = -L/app/cny/bin -L$(ORACLE_HOME)/lib -L$(ORACLE_HOME)/rdbms/lib -L$(CNY_HOME)/lib -ldatagent
# libraries for linking oci programs
OCISHAREDLIBS= $(ORACLE_HOME)/lib/libclntsh.a
OCISTATICLIBS= $(STATICTTLIBS) $(LLIBTHREAD)
LIBCC = -X64 -p -100 -bglink:/lib/glink64.o -bM:SRE
COMPILE_C =$(CC) -g $(DEFS) $(INCLUDE)
COMPILE_CPP =$(CPP) -g $(DEFS) $(INCLUDE)
LINK =$(CPP) -g -qmkshrobj $(LDFLAGS) $(OCISHAREDLIBS) $(LIBPATH) $(LIBORB) $(STDCC_LIBS)
# Add exe filename and source filename
TARGET1=ExhCatg.so.1 Carrier.so.1
#TARGET1= SplitAreaCode.so.1
# Add target name
all: $(TARGET1) $(depends) $(lint)
ExhCatg :ExhCatg.so.1 $(depends) $(lint)
Carrier :Carrier.so.1 $(depends) $(lint)
#C++ SOURCE FILES
SRC_CPP =CNYCommon.cpp Memory.cpp String.cpp StringArray.cpp PtrArray_t.cpp Common.cpp Oracle.cpp OracleDB.cpp
LsCorba.cpp LsCorbaAgent.cpp SocketPlus.cpp LXml.cpp Agent.cpp ServiceStat.cpp ServiceMessage.cpp
Thread.cpp Carrier.cpp ExhCatg.cpp
#C++ OBJECT FILES
OBJ_CPP = $(SRC_CPP:.cpp=.o)
#C SOURCE FILES
SRC_C =
#C++ OBJECT FILES
OBJ_C = $(SRC_C:.c=.o)
#.SUFFIXES: .o .cpp .c .idl
.SUFFIXES: .o .cpp .c
.cpp.o:
$(COMPILE_CPP) -c -o $@ $