带静态库的C ++未定义引用

时间:2016-08-10 04:00:06

标签: c++ reference static undefined

我得到了未定义的引用'用静态库编译代码时。我搜索了很多回答,告诉我们使用extern" C"或者在编译时更正参数的顺序,但这些并不能解决我的问题。 我有这些:

compiler.hpp

#ifndef COMPILER_H
#define COMPILER_H

int buildTree();

#endif

compile.cpp

#include <compiler.hpp>

int buildTree() {

     Package package = new Package();

}

还有很多其他源代码,然后我通过使用-c标志将它们构建到.o文件中来构建它们到lib.a:

ar rvs lib.a $(OBJS)

我的Main.cpp:

#include <compiler.hpp>

int main() {

     buildTree();

}

最后,我构建了可执行文件:

LIBS = lib.a

main: main.cpp
$(CPP) $(CPPFLAGS) $(LIBDIR) $^ $(LIBS) -o $@

但是g ++ complier抛出了这个错误:

undefined reference to `buildTree()'

0 个答案:

没有答案
相关问题