Compiling project with C++ Actor Framework in Ubuntu 14

With Ubuntu 14, I tried to compile the hello_world with my own makefile but resulted in errors such as these:

hello_world.o:(.rodata._ZTIN3caf6detail18basic_memory_cacheINS_17event_based_actorEE7storageE[_ZTIN3caf6detail18basic_memory_cacheINS_17event_based_actorEE7storageE]+0x10): undefined reference to `typeinfo for caf::ref_counted'
hello_world.o:(.rodata._ZTIN3caf6detail18basic_memory_cacheINS0_12pair_storageINS_15mailbox_elementENS0_10tuple_valsIISsEEEEEE7storageE[_ZTIN3caf6detail18basic_memory_cacheINS0_12pair_storageINS_15mailbox_elementENS0_10tuple_valsIISsEEEEEE7storageE]+0x10): undefined reference to `typeinfo for caf::ref_counted'
hello_world.o: In function `caf::detail::basic_memory_cache::storage::~storage()':
hello_world.cpp:(.text._ZN3caf6detail18basic_memory_cacheINS_17event_based_actorEE7storageD2Ev[_ZN3caf6detail18basic_memory_cacheINS_17event_based_actorEE7storageD5Ev]+0x56): undefined reference to `caf::ref_counted::~ref_counted()'
hello_world.o: In function `caf::detail::basic_memory_cache<caf::detail::pair_storage<caf::mailbox_element, caf::detail::tuple_vals > >::storage::~storage()':
hello_world.cpp:(.text._ZN3caf6detail18basic_memory_cacheINS0_12pair_storageINS_15mailbox_elementENS0_10tuple_valsIISsEEEEEE7storageD2Ev[_ZN3caf6detail18basic_memory_cacheINS0_12pair_storageINS_15mailbox_elementENS0_10tuple_valsIISsEEEEEE7storageD5Ev]+0x53): undefined reference to `caf::ref_counted::~ref_counted()'
collect2: error: ld returned 1 exit status

Turns out just a newbie mistake. I needed to include the lib files with -lcaf_io -lcaf_core and use the -std=c++11 flag. Also, before running the executable, do export LD_LIBRARY_PATH=/usr/local/lib in order to load the dynamic libraries, assuming the libraries are installed to the default location. Below is my makefile.

CC=g++
CFLAGS=-c -Wall -std=c++11
LDFLAGS=
SOURCES=hello_world.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) -o $@ -lcaf_io -lcaf_core

.cpp.o:
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -f $(EXECUTABLE) *.o
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s