怎么写 makefile
有一堆源文件
- |--inc / *.h
|--src / *.h *.cpp
|--bin /
|--prj / Makefile
|--lib /
|--Makefile
其中 inc 中的头文件是公开出去的, src 里面的头文件是私有的。
prj 的 Makefile:
add_cflags = -I../inc
cxxsources = \
../src/*.cpp \
……
csources = \
sources = $(cxxsources) $(csources)
include ../Makefile
外部的 Makefile:
release: $(sources)
g++ -g -c -Os -fPIC -lrt -lpthread $(add_cflags) $(sources)
在生成 .o (目标文件)时, 都生成了,但是最后报了一个错,没具体信息:
在 prj/ 下 执行: make release
make: *** [release] 错误 1
然后我生成 动态库:
$ g++ -shared -o ../bin/libxxx.so *.o
在 bin/ 目录下生成了 libxxx.so
然后我写了个测试代码 调用了 libxxx.so 的函数,编译时,
/bin/libxxx.so: undefined reference to `*****` (libxxx.so 里的函数)
生成的动态库无效? 请问这个问题怎么解决?
bin/libxxx.so: undefined reference to `*****`
这个函数在哪个文件,确定编译了没有
看样子是一些系统的函数,在编译动态库的时候 是 有 -lpthread 和 -lrt 的,在编译这个test 的时候也加了,为什么还会提示这个?
我发现对动态库的引用还有顺序。