C++ modularized project linking issues and undefined reference error - c++

I am having trouble figuring out how to build out a modularized c++ app and getting everything to link up properly. Specifically, I can't get some tests to build because ultimately I get an undefined reference error based on a class method. (I am new to c++ and CMake so I'm probably doing a lot wrong, but I'm learning!) I have gone through other posts and all I can glean is that I'm potentially not linking properly.
Both OrderBook and Strategy build just fine. However, when I go to build StrategyTests and OrderBookTests I get an error:
[ 83%] Linking CXX executable StrategyTests.exe
../../OrderBook/libOrderBook.a(OrderBook.cpp.o): In function `orderbook::OrderBook::notify_strategies(std::shared_ptr<orderbook::Order> const&, bool)':
/cygdrive/d/Dropbox/My Documents/Programming/CLionProjects/TradingSystem/OrderBook/OrderBook.cpp:220: undefined reference to `HYSTRAT::Strategy::onBookUpdate(std::shared_ptr<Events::TOB> const&, std::shared_ptr<Events::OrderBookEvent> const&, bool)'
/cygdrive/d/Dropbox/My Documents/Programming/CLionProjects/TradingSystem/OrderBook/OrderBook.cpp:220:(.text+0x11c4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `HYSTRAT::Strategy::onBookUpdate(std::shared_ptr<Events::TOB> const&, std::shared_ptr<Events::OrderBookEvent> const&, bool)'
collect2: error: ld returned 1 exit status
I've tried a number of different things including fiddling with CMakeLists and headers, but none seem to work. It's pretty clear I don't know the true meaning of "undefined reference". I suspect this is an easy fix, but I posted the project setup below in case it's not.
Here's my setup:
Clion and Cygwin on Windows 10
Project Tree
TradingSystem
|-CMakeLists.txt
|\OrderBook
|-|-CMakeLists.txt
|-|-OrderBook.h
|-|-OrderBook.cpp
|\Strategy
|-|-CMakeLists.txt
|-|-Strategy.h
|-|-Strategy.cpp
|\Tests
|-|-CMakeLists.txt
|-|\OrderBookTests
|-|-|-CMakeLists.txt
|-|-|\BoostTests
|-|-|-|-CMakeLists.txt
|-|-|-|-OrderBookBoostTests.cpp
|-|\StrategyTests
|-|-|-CMakeLists.txt
|-|-|-StrategyBoostTests.cpp
CMakes
#TradingSystem/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(TradingSystem)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(TradingSystem ${SOURCE_FILES} ${HEADER_FILES})
include_directories(OrderBook Strategy Events)
add_subdirectory(OrderBook)
add_subdirectory(Strategy)
add_subdirectory(Events)
add_subdirectory(Tests/OrderBookTests)
add_subdirectory(Tests/StrategyTests)
target_link_libraries(TradingSystem OrderBook Strategy)
-
#TradingSystem/OrderBook/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(OrderBook)
include_directories(/cygdrive/c/Program Files/boost/boost_1_66_0)
set(CMAKE_CXX_STANDARD 11)
set(HEADER_FILES OrderBook.h)
set(SOURCE_FILES OrderBook.cpp)
add_library(OrderBook STATIC ${SOURCE_FILES} ${HEADER_FILES})
-
#TradingSystem/Strategy/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Strategy)
include_directories(/cygdrive/c/Program Files/boost/boost_1_66_0)
set(CMAKE_CXX_STANDARD 11)
set(HEADER_FILES Strategy.h)
set(SOURCE_FILES Strategy.cpp)
add_library(Strategy STATIC ${SOURCE_FILES} ${HEADER_FILES})
-
#TradingSystem/Tests/CMakeLists.txt
project(Tests)
add_subdirectory(OrderBookTests)
add_subdirectory(StrategyTests)
-
#TradingSystem/Tests/OrderBookTests/CMakeLists.txt
project(OrderBookTests)
add_subdirectory(BoostTests)
[EDIT]
#TradingSystem/Tests/OrderBookTests/BoostTests/CMakeLists.txt
add_executable(BoostTests OrderBookBoostTests.cpp)
enable_testing()
include_directories(/cygdrive/c/Program Files/boost_1_66_0)
set(BOOST_ROOT "C:/Program Files/boost_1_66_0/")
set(BOOST_LIBRARYDIR "C:/Program Files/boost_1_66_0/")
find_package(Boost 1.66.0)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${BOOSTROOT})
link_directories("${BOOSTROOT}")
target_include_directories(OrderBook PRIVATE ${BOOST_INCLUDE_DIRS})
# Original:
# target_link_libraries(BoostTests OrderBook)
# Changed to:
target_link_libraries(BoostTests Orderbook Strategy)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
[EDIT]
#TradingSystem/Tests/StrategyTests/CMakeLists.txt
project(StrategyTests)
add_executable(StrategyTests StrategyBoostTests.cpp)
enable_testing()
include_directories(/cygdrive/c/Program Files/boost_1_66_0)
set(BOOST_ROOT "C:/Program Files/boost_1_66_0/")
set(BOOST_LIBRARYDIR "C:/Program Files/boost_1_66_0/")
find_package(Boost 1.66.0)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${BOOSTROOT})
link_directories("${BOOSTROOT}")
target_include_directories(Strategy PRIVATE ${BOOST_INCLUDE_DIRS})
# Original:
# target_link_libraries(StrategyTests Strategy OrderBook)
# Change to:
target_link_libraries(StrategyTests Orderbook Strategy)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
The Src Files
#TradingSystem/OrderBook/OrderBook.h
#fndef TRADINGSYSTEM_ORDERBOOK_H
#define TRADINGSYSTEM_ORDERBOOK_H
#include <vector>
using std::vector;
#include "Strategy.h"
#include "Events.h"
namespace orderbook {
/////////////////////
// HIDDEN CODE
/////////////////////
class OrderBook {
private:
vector<HYSTRAT::Strategy> strategies_;
bool notify_strategies(const order_ptr& o, bool add_flag);;
Events::order_book_event_ptr create_order_book_event(const order_ptr& order);;
public:
/////////////////////////////
// CONSTRUTORS; DESTRUCTORS
/////////////////////////////
inline bool subscribe(HYSTRAT::Strategy& s) {
strategies_.push_back(s);
}
#endif //TRADINGSYSTEM_ORDERBOOK_H
-
#TradingSystem/OrderBook/OrderBook.cpp
#include "OrderBook.h"
#include "Events.h"
#include "Strategy.h"
using orderbook::OrderBook;
using HYSTRAT::Strategy;
bool orderbook::OrderBook::notify_strategies(const order_ptr& o, bool add_flag) {
try {
Events::order_book_event_ptr event = create_order_book_event(o);
Events::topOfBook_ptr tob = get_top_of_book();
for (HYSTRAT::Strategy& strategy : strategies_) {
strategy.onBookUpdate(tob, event, add_flag);
}
return true;
} catch (const std::exception& e) {
return false;
}
}
-
#TradingSystem/Strategy/Strategy.h
#ifndef TRADINGSYSTEM_STRATEGY_H
#define TRADINGSYSTEM_STRATEGY_H
#include "Events.h"
namespace HYSTRAT {
class Strategy {
public:
void onBookUpdate(const Events::topOfBook_ptr& tob, const Events::order_book_event_ptr& e, bool event_flag);;
};
}
#endif //TRADINGSYSTEM_STRATEGY_H
-
#TradingSystem/Strategy/Strategy.cpp
#include "OrderBook.h"
#include "Strategy.h"
#include "Events.h"
using namespace HYSTRAT;
void Strategy::onBookUpdate(const Events::topOfBook_ptr &tob, const Events::order_book_event_ptr &e, bool event_flag) {
if (tob->bidP >= tob->offerP) {
quantity_t order_size = std::min(tob->offerQ, tob->bidQ);
order_ptr buy_order(new Order(tob->offerP, order_size, BUY));
order_ptr sell_order(new Order(tob->bidP, order_size, SELL));
send_order(buy_order);
send_order(sell_order);
}
}

I think you are missing a few calls to "add_dependencies" in your CMakeLists.txt files. I think this particular problem might be solved by adding
add_dependencies(OrderBook Strategy)
to your Orderbooks CMakelists.txt

Related

Why is EXPECT_CALL causing a read access violation GMock?

EDIT: I'm not the only one having this issue, maybe it's VS https://github.com/google/googletest/issues/2628
I'm having trouble getting GMock setup correctly. I'm using Windows and CMake, and adding GMock to my existing project.
The code that I'm trying to run is:
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::AnyNumber;
namespace ifac
{
class Foo
{
public:
virtual ~Foo() = default;
virtual void Bar(int i) = 0;
};
class FooMock : public Foo
{
public:
MOCK_METHOD1(Bar, void(int));
};
TEST(FooTest, BarCalled)
{
FooMock m;
EXPECT_CALL(m, Bar(1)).Times(AnyNumber());
m.Bar(1);
}
}
When it runs I get an error saying:
Exception thrown: read access violation. this was 0xFFFFFFFFFFFFFFFB.
The error is in the void Mutex::ThreadSafeLazyInit() of gtest-port.cc.
This seems to only happen if I set CMAKE_CXX_STANDARD to 17 too. I'm not really sure where to start with this, since I don't know a lot about C++, CMake or gtest/gmock.
Here's a stripped down version of the CMakeLists.txt files I have.
cmake_minimum_required (VERSION 3.8)
project ("TestingDemo")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
enable_testing()
add_subdirectory("googletest")
add_executable(Tests
"Main.cpp"
"Tests.cpp")
target_link_libraries(Tests PUBLIC gtest gtest_main gmock gmock_main)
add_test(RunTests Tests)

Getting "undefined reference to"

I tried several things to resolve this issue, but I just can't get my head around CMake apparently...
The following is basically the entire project:
.
├── CMakeLists.txt
└── src
├── CMakeLists.txt
├── main.cpp
├── SubwordEncoder.cpp
└── SubwordEncoder.h
The first (./CMakeLists.txt) contains:
cmake_minimum_required(VERSION 3.5)
project(xlib)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(./src)
add_executable(main src/main.cpp)
and the second (src/MakeLists.txt)
file(GLOB_RECURSE xlib_SOURCES "*.cpp")
file(GLOB_RECURSE xlib_SURCES "*.h")
main.cpp only contains this:
#include <string>
#include <iostream>
#include <stdio.h>
#include "SubwordEncoder.h"
int main() {
std::cout << "Hello World!" << std::endl;
auto encoder = new SubwordEncoder();
auto encoded = encoder->encode("Hello World!");
for (auto i : encoded) {
std::cout << i << std::endl;
}
return 0;
}
SubwordEncoder.h
#ifndef XLIB_SUBWORDENCODER_H
#define XLIB_SUBWORDENCODER_H
#include <string>
#include <vector>
class SubwordEncoder {
public:
std::vector<int> encode(std::string decoded);
};
#endif //XLIB_SUBWORDENCODER_H
and SubwordEncoder.cpp
#include "SubwordEncoder.h"
std::vector<int> SubwordEncoder::encode(std::string decoded) {
std::vector<int> vect;
vect.push_back(10);
vect.push_back(20);
vect.push_back(30);
return vect;
}
Yet I keep getting this error:
/tmp/tmp.KYl9HEcObN/src/main.cpp:13: undefined reference to `SubwordEncoder::encode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
What am I doing wrong?
Note:
I know I could do this:
add_executable(main src/main.cpp src/SubwordEncoder.cpp src/SubwordEncoder.h)
but I don't want to add every single file here. I want all files in src/ to be used for the compilation.
When you call add_executable(), you are only including main.cpp and not the others, so SubwordEncoder::encode is undefined when you try to use it in main(). Try changing your CMake files to something like this:
./CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(xlib)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(src)
./src/CMakeLists.txt
file(GLOB_RECURSE xlib_SOURCES "*.cpp")
file(GLOB_RECURSE xlib_HEADERS "*.h")
add_executable(main ${xlib_SOURCES} ${xlib_HEADERS})
# Include the current folder for including headers.
target_include_directories(main PRIVATE ${CMAKE_CURRENT_LIST_DIR})
The only line in either of your CMake files that actually causes files to be compiled is add_executable(main src/main.cpp) and the only file it adds is main.cpp. There is nothing in either CMake file that actually tells it to compile the other source files.
These lines
file(GLOB_RECURSE xlib_SOURCES "*.cpp")
file(GLOB_RECURSE xlib_HEADERS "*.h")
only set up variables containing lists of file names. There is nothing that then includes those files in any compilation. Your options are either add those files to your compilation of the main target as in squareskittles answer, or compile them as a separate library and then link it into main:
src/CMakeLists.txt:
add_library(SubwordEncoder ${xlib_SOURCES})
./CMakeLists.txt:
target_link_libraries(main SubwordEncoder)

Catch2 - undefined reference to

I'm testing my project using Catch2 as library. I followed every step in the Catch doc, but when I run the tests I get the following error:
CMakeFiles/tests.dir/tests/IntegerIntervalTest.cpp.o: in function "____C_A_T_C_H____T_E_S_T____0()":
/home/davide/cpp-project/tests/IntegerIntervalTest.cpp:8: undefined reference to "domain::IntegerAbstractInterval<int, int>::IntegerAbstractInterval(int, int)"
and this error repeates for every method call in the test "class".
CMakeLists:
PROJECT(cpp_project)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
IF (COMPILER_SUPPORTS_CXX14)
ADD_COMPILE_OPTIONS("-std=c++14")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++14 support.")
ENDIF ()
set(BASE_SRCS src/Bound.cpp src/Bound.hpp src/Infinity.cpp src/Infinity.hpp src/AbstractInterval.cpp src/AbstractInterval.hpp
src/UndefinedOperationException.hpp src/IntegerAbstractInterval.cpp src/IntegerAbstractInterval.hpp src/FloatingPointAbstractInterval.cpp
src/FloatingPointAbstractInterval.hpp)
ADD_COMPILE_OPTIONS("-Wall" "-Wextra" "-Wpedantic" "-Werror" )
ADD_LIBRARY(cpp-project ${BASE_SRCS})
INCLUDE_DIRECTORIES(libs/variant/include)
set(EXECUTABLE_OUTPUT_PATH bin)
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
set(TEST_SRCS tests/InfinityTest.cpp tests/IntegerIntervalTest.cpp)
add_executable(tests ${BASE_SRCS} ${TEST_SRCS})
target_link_libraries(tests Catch)
and this is the test file IntegerIntervalTest.cpp:
#include "../src/IntegerAbstractInterval.hpp"
#include "../libs/catch2/catch.hpp"
using namespace domain;
TEST_CASE("Operations on IntegerInterval instances", "[IntegerAbstractInterval]") {
IntegerAbstractInterval<int, int> i(0,1);
IntegerAbstractInterval<Infinity, Infinity> ii(Infinity('-'), Infinity('+'));
IntegerAbstractInterval<Infinity, int> iii(Infinity('-'), 5);
IntegerAbstractInterval<int, Infinity> iv(0, Infinity('+'));
IntegerAbstractInterval<int, int> v(-1,1);
SECTION("Sum operations") {
auto res1 = i + v;
REQUIRE(res1.getLowerBound() == Bound(-1));
REQUIRE(res1.getUpperBound() == Bound(2));
}
}
I had the same problem and it was fixed by firstly defining the #define and then the #include:
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
A nice tutorial on setting up and using Catch2 is provided by JetBrains for CLion IDE.

Creating cmake install macro for a library

This my project structure:
main
|
--src
|
--feed.h
--feed.cc
--other files
--CMakeLists2.txt
--test
|
--test.cpp
--CMakeLists3.txt
CMakeLists1.txt
CMakeLists1.txt
cmake_minimum_required (VERSION 2.8.11)
project (Feedparser)
set(CMAKE_MODULE_PATH cmake)
find_package(PTHREAD REQUIRED)
find_package(CURL REQUIRED)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
add_subdirectory (src)
add_subdirectory (test)
CMakeLists2.txt
cmake_minimum_required (VERSION 2.8.11)
add_library (Feedparser news.h xml2json.hpp jsonxx.cc curler.cc feed.cc )
target_link_libraries(Feedparser pthread)
target_link_libraries(Feedparser curl)
install(TARGETS Feedparser
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION /usr/lib)
install(FILES "feed.h" DESTINATION /usr/include )
target_include_directories (Feedparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
CMakeLists3.txt
cmake_minimum_required (VERSION 2.8.11)
add_executable(Feedtest test.cc)
target_link_libraries (Feedtest LINK_PUBLIC Feedparser)
Here is my Header file.
feed.h
#include "news.h"
#include "curler.cc"
#include "jsonxx.h"
#include "jsonxx.cc"
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <thread>
#include <stdio.h>
using namespace std;
using namespace jsonxx;
class feed{
map <string,string> info;
std::map<int, Object> items;
string url;
news News;
Object *item;
void strip_items();
public:
Object json;
feed(string url);
void create(string url){
this->url = url;
}
feed(){}
string get_topic(){
return info["title"];
}
bool fetch();
bool fetch_data();
bool parse();
string get_url(){
return url;
}
string get_item_title(int index){
return News.title[index];
}
string get_item_img(int index){
return News.image[index];
}
string get_item_link(int index){
return News.link[index];
}
int get_total(){
return News.num_item;
}
struct news get_news(){
return News;
}
};
Should I include feed.h in feed.cc and compile and how does the compiler directly link .h files with the .cxx files in archives?
How do i write a cmake script for installing this library?
Where is my mistake?
C++'s building process consists of 2 stages:
Compilation: The compiler runs on every source (.cc) file, generating an intermidiate binary.
Linking: The linker runs on every intermidiate binary, matching declarations with definitions.
Finally, it combines all of them to make the final binary.
With this in mind, you need to make sure the compiler doesn't come across something that it doesn't know about. That's why you include headers (.h).
The linker should be fed with everything the compiler creates.

CMAKE LINKING ERROR with a user-defined shared library

I am a newcomer to the world of cmake. This question came up while I was experimenting with some basic cmake configurations in C++. To be precise, following is my directory structure :
/src----
|-> CMakeLists.txt
|-> main.cpp
|-> lib----
|-> libfsystem.so
|->filesystem----
|->CMakeLists.txt
|->listfiles.cpp
|->include-----
|->fsystem.h
Now, the /src/filesystem/CMakeLists.txt file is like this
cmake_minimum_required(VERSION 2.8)
project(fsystem)
set(CMAKE_BUILD_TYPE Release)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build)
find_package(Boost REQUIRED system filesystem)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(fsystem SHARED listfiles.cpp)
While, the /src/CMakeLists.txt file is like this
cmake_minimum_required(VERSION 2.8)
project(vessel_detect)
add_subdirectory(filesystem)
add_executable(main main.cpp)
set(CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
find_library(libpath fsystem)
MESSAGE(${libpath})
target_link_libraries(main ${libpath})
The library libfsystem.so is successfully created.
The library libfsystem.so is also successfully found by /src/CMakeLists.txt
However when the linking of main.cpp is done, then it gives me several undefined reference errors which should not have happened as everything has already been defined. For greater completeness, following is the content of main.cpp file
Main.cpp
#include<iostream>
#include"filesystem/include/fsystem.h"
using namespace std;
int main(void)
{
string path ("~");
vector<string>* output;
output = listfiles(path);
return 0;
}
The contents of listfiles.cpp are
listfiles.cpp
#include"fsystem.h"
using namespace boost::filesystem;
vector<string>* listfiles(int argc, char* argv[])
{
if (argc<2)
{
std::cout<<"No file name provided"<<std::endl;
}
else
{
path p(argv[1]);
vector<string>* output;
if (exists(p))
{
if(is_directory(p))
{
std::cout<<"You specified a directory"<<std::endl;
std::cout<<"Its contents are as follows :-"<<std::endl;
typedef std::vector<path> vec;
vec v;
copy(directory_iterator(p),directory_iterator(),back_inserter(v));
sort(v.begin(),v.end());
for(vec::const_iterator it(v.begin());it!=v.end();++it)
output->push_back(it->filename().string());
// std::cout<<it->filename()<<std::endl;
}
else if (is_regular_file(p))
{
std::cout<<argv[1]<<" "<<file_size(p)<<std::endl;
}
else
{
std::cout<<"The file is neither a directory nor a regular file"<<std::endl;
}
}
else
{
std::cout<<"The speicified path does not exist"<<std::endl;
}
}
}
And finally, the fsystem.h contents are :
fsystem.h
#ifndef _fsystem_h
#define _fsystem_h
#include<iostream>
#include<string>
#include<vector>
#include"boost/filesystem.hpp"
using namespace std;
vector<string>* listfiles(string);
#endif
Could someone provide me a reason for the undefined reference errors I am getting during the linking of main.cpp ? I would also be grateful if you could provide me with a resolution of this issue.
Thanks
Your not linking boost. you need to add target_link_libraries(fsystem ${Boost_LIBRARIES}) to the end of /src/filesystem/CMakeLists.txt and include_directories(${Boost_INCLUDE_DIRS}) between the find_package and add_library.
cmake_minimum_required(VERSION 2.8)
project(fsystem)
set(CMAKE_BUILD_TYPE Release)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build)
find_package(Boost REQUIRED system filesystem)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${Boost_INCLUDE_DIRS})
add_library(fsystem SHARED listfiles.cpp)
target_link_libraries(fsystem ${Boost_LIBRARIES})
(1) For TARGET_LINK_LIBRARIES you should put the name of the target, thus:
TARGET_LINK_LIBRARIES(main fsystem)
(2) You declare listfiles as vector<string>* listfiles(string) while you define it as vector<string>* listfiles(int,char**)
Additionally you need to link with Boost per the other reply.