我有两组文件:PolynomialArithmetic.h/cpp 和 Options.h/cpp
Options.h 定义为:
// Options.h
#ifndef Options_h
#define Options_h
#define BINARY_HEAP 0
inline int chosenHeap ();
#endif
Options.cpp 定义为:
// Options.cpp
#include "Options.h"
inline int chosenHeap() { return BINARY_HEAP; }
PolynomialArithmetic.cpp 包含以下内容:
// PolynomialArithmetic.cpp
#include "PolynomialArithmetic.h"
#include "Options.h"
void foo () {
...
if (chosenHeap() == BINARY_HEAP) {
// DO SOMETHING
}
...
}
当我编译时,我收到错误:
Undefined symbols for architecture x86_64:
"chosenHeap()", referenced from: foo() in PolynomialArithmetic.o
我猜这是某种链接错误。这是我编译代码的方式:
# Makefile
# some configs
....
main: Options.o PolynomialArithmetic.o
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
Options.o: Options.h Options.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c Options.cpp
PolynomialArithmetic.o: PolynomialArithmetic.cpp PolynomialArithmetic.h Options.h
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c PolynomialArithmetic.cpp
有任何想法吗?