Makefile with STXXL

♀尐吖头ヾ 提交于 2019-12-13 20:53:10

问题


I need to use the STXXL library for a software project I am working on, but for some reason, I am having trouble compiling a test file. I am not very familiar with makefiles, so I might have mixed up in linking some of the libraries together.

The dummy files I am using are Draw.h, Draw.cpp, and driver.cpp. As you can imagine, Draw.h declares a method draw() that is implemented in Draw.cpp, and driver.cpp contains the main function, and includes Draw.h and calls draw().

The makefile I am using is:

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

The error I am getting is

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

Any ideas?


回答1:


In this rule:

my_example.bin: driver.o Draw.o
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) driver.o -o $@ $(LDLIBS)

you require that Draw.o exist, but you're not linking it in. Try this:

my_example.bin: driver.o Draw.o
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) driver.o Draw.o -o $@ $(LDLIBS)

or more concisely:

my_example.bin: driver.o Draw.o
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)


来源:https://stackoverflow.com/questions/9558648/makefile-with-stxxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!