5

I'm testing boost's memory mapped files, but as soon as I declare a boost::iostreams::mapped_file, like in this program:

#include <ff/pipeline.hpp> // defines ff_pipeline and ff_Pipe
#include <ff/farm.hpp>
#include <iostream>
#include <iterator>
#include <sstream>
#include <stdlib.h>
#include <time.h>

#include <boost/iostreams/device/mapped_file.hpp>

#include "MapReduceJob.hpp"

using namespace ff;

int main(int argc, char* argv[]) {
    boost::iostreams::mapped_file  mf;
} 

Using this makefile:

#Fastflow and Boost paths
FF_ROOT     = ../../fastflow
BOOST_ROOT  = ../../boost_1_59_0

#Xeon's user
USR = spm1428

#Accelerator
ACC = mic0

#Program arguments
ARGS =

#Test script file
TEST = test

#file to copy on $(ACC)
FILES = file.txt foo.txt

# compiler
CC = icpc -mmic

# compiler flag
CXX = $(CC) -std=c++11 -DNO_DEFAULT_MAPPING

# compile-time flags
CFLAGS =

# header files other than /usr/include
INCLUDES = -I$(FF_ROOT)  -I$(BOOST_ROOT)

# define any libraries to link into executable:
LIBS = -pthread

#optimization flags
OPTFLAGS = -O3 -finline-functions -DNDEBUG -g -O0

# define the C source files
SRCS = Main.cpp

# define the C object files 
OBJS = $(SRCS:.cpp=.o)

# define the executable file 
MAIN = mapreduce


.PHONY: all depend clean

all:    $(MAIN) copy execute
    @echo  Simple compiler named mycc has been compiled

$(MAIN): $(OBJS) 
    $(CXX) $(CFLAGS) $(INCLUDES) $(OPTFLAGS) -o $(MAIN) $(OBJS) $(LIBS)

copy:
    scp $(FILES) $(TEST) $(MAIN) $(USR)@$(ACC):~

execute:
    ssh $(USR)@$(ACC) ./$(MAIN) $(ARGS)

test:
    ssh $(USR)@$(ACC) ./$(TEST)

.cpp.o:
    $(CXX) $(CFLAGS) $(INCLUDES) -c $<  -o $@

clean:
    $(RM) *.o *~ $(MAIN)

depend: $(SRCS)
    makedepend $(INCLUDES) $^

# DO NOT DELETE THIS LINE -- make depend needs it

I get this compile error:

make CC=g++ mapreduce 
g++ -std=c++11 -DNO_DEFAULT_MAPPING  -I../../fastflow  -I../../boost_1_59_0 -c Main.cpp  -o Main.o
g++ -std=c++11 -DNO_DEFAULT_MAPPING  -I../../fastflow  -I../../boost_1_59_0 -O3 -finline-functions -DNDEBUG -g -O0 -o mapreduce Main.o -pthread
Main.o: In function `boost::iostreams::mapped_file::mapped_file()':
Main.cpp:(.text._ZN5boost9iostreams11mapped_fileC2Ev[_ZN5boost9iostreams11mapped_fileC5Ev]+0x24): undefined reference to `boost::iostreams::mapped_file_source::mapped_file_source()'
collect2: error: ld returned 1 exit status
make: *** [mapreduce] Error 1

Up to now boost worked fine (for example using boost::posix_time::ptime Time or boost::stringref).

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138

1 Answers1

5

You aren't linking to boost. Just including the header files is only half of what you need to do.

Change this in your Makefile:

LIBS = -pthread -L(path to boost libraries) -lboost_iostreams

This should link the boost_iostreams library to your final executable.

Depending on your platform and setup, you may have to add the library path to an environment variable.

Dovahkiin
  • 946
  • 14
  • 25