我需要将 STXXL 库用于我正在处理的软件项目,但由于某种原因,我在编译测试文件时遇到了麻烦。我对 makefile 不是很熟悉,所以我可能混淆了将一些库链接在一起。
我使用的虚拟文件是 Draw.h、Draw.cpp 和 driver.cpp。可以想象,Draw.h声明了一个方法draw(),在Draw.cpp中实现,driver.cpp包含main函数,包含Draw.h并调用draw()。
我使用的makefile是:
STXXL_ROOT ?= /Users/name/stxxl-1.3.1
STXXL_CONFIG ?= stxxl.mk
include $(STXXL_ROOT)/$(STXXL_CONFIG)
# use the variables from stxxl.mk
CXX = $(STXXL_CXX)
CPPFLAGS += $(STXXL_CPPFLAGS)
LDLIBS += $(STXXL_LDLIBS)
# add your own optimization, warning, debug, ... flags
# (these are *not* set in stxxl.mk)
CPPFLAGS += -O3 -Wall -g -DFOO=BAR
# build your application
# (my_example.o is generated from my_example.cpp automatically)
my_example.bin: driver.o Draw.o
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) driver.o -o $@ $(LDLIBS)
driver.o: driver.cpp Draw.h
$(CXX) $(CXXFLAGS) -c driver.cpp
Draw.o: Draw.cpp Draw.h
$(CXX) $(CXXFLAGS) -c Draw.cpp
我得到的错误是
g++ -I/Users/name/stxxl-1.3.1/include -include stxxl/bits/defines.h -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -O3 -Wall -g -DFOO=BAR driver.o -o my_example.bin -L/Users/name/stxxl-1.3.1/lib -lstxxl
Undefined symbols for architecture x86_64:
"draw(int)", referenced from:
_main in driver.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [my_example.bin] Error 1
有任何想法吗?