CMake can find my version of boost installed (1.67.0) but whenever I try to link a library I get a ton of "undefined reference".
This is the program that I want to run (the example found on boost's website):
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main(int, char *[])
{
std::string line;
boost::regex pat("^Subject: (Re: |Aw: )*(.*)");
while(std::cin) {
std::getline(std::cin, line);
boost::smatch matches;
if(boost::regex_match(line, matches, pat)) {
std::cout << matches[2] << '\n';
}
}
return 0;
}
This is my CMake script:
cmake_minimum_required( VERSION 3.5 )
project( REGEX )
set( BOOST_ROOT D:/Dev/boost/boost_1_67_0/boost_1_67_0 )
set( Boost_LIBRARY_DIR D:/Dev/boost/boost_1_67_0/boost_1_67_0/stage/lib )
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED ON )
find_package( Boost REQUIRED )
include_directories( ${Boost_INCLUDE_DIRS} )
add_executable( regex ${PROJECT_SOURCE_DIR}/main.cxx )
target_link_libraries( regex ${Boost_LIBRARIES} )
What do I need to do to successfully link boost libraries with cmake?
EDIT: I've changed the script so now it looks like this:
cmake_minimum_required( VERSION 3.5 )
project( REGEX )
set( BOOST_ROOT D:/Dev/boost/boost_1_67_0/boost_1_67_0 )
set( BOOST_INCLUDEDIR D:/Dev/boost/boost_1_67_0/boost_1_67_0/boost )
set( BOOST_LIBRARYDIR D:/Dev/boost/boost_1_67_0/boost_1_67_0/stage/lib )
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED ON )
set( Boost_DEBUG ON )
find_package( Boost COMPONENTS regex REQUIRED )
include_directories( ${Boost_INCLUDE_DIRS} )
add_executable( regex ${PROJECT_SOURCE_DIR}/main.cxx )
target_link_libraries( regex ${Boost_LIBRARIES} )
After enabling debugging for boost I saw cmake didn't have any directory to search for the libraries so I've tried to set it manually. I've just installed the 3.11.1 version of CMake but it still doesn't recognize the regex library.