[CMake] linking boost to cmake under OSX 10.12.1 , boost 1.63 , cmake 2017.11

Michael Ellery mellery451 at gmail.com
Thu May 4 01:32:09 EDT 2017


> On May 3, 2017, at 8:20 PM, Sean Wayland <seanwayland at gmail.com> wrote:
> 
> Hi all,
> 
> I am very new to cmake and boost. Sorry if my question is basic thanks for your help in advance. 
> 
> I am having trouble linking a project to boost. I am using OSX 10.12.1 
> I am using clion 2017.1.1 
> 
> I installed boost on my machine using /bootstrap.sh --prefix=/usr/local/boost --with-libraries=filesystem,system
> 
> I also tried a brew install boost also . 
> 
> Boost can indeed be found here usr/local/boost/ on my machine. 
> 
> I haven't had much luck getting boost to link properly. 
> 
> I believe the project uses the filesystem and tuple modules. 
> 
> I am getting this error 
> 
> CMake Error at CMakeLists.txt:557 (ADD_EXECUTABLE):
>   Cannot find source file:
> 
>     anyExecutable.cpp
> 


This error means that it can’t find the named source file. The path is relative to the CMakeLists.txt file in which you define the target. Does that source file exist in that location? 


> From what I have read I think that if you are using OSX that you have to use the FIND_PACKAGE command to link things properly. I suspect that the code below doesn't work because I need to properly place the exact filesystem location of the executable file created in the add_executable command. 
> On a positive note I did get this message 
> -- Boost version: 1.63.0
> -- Found the following Boost libraries:
> --   program_options
> -- Configuring done
> 

This indicates that it found some version of boost, but it seems only the program_options library. I would add message(“$Boost_LIBRARIES”) after your find_package() statement to print out the location of the found libraries to see if that matches your expectation. I generally prefer to do a full staged build of boost from source..that typically looks like “./bootstrap.sh && ./b2 stage” — and I then I point to that staged build using a BOOST_ROOT environment variable (the CMake boost finder will honor BOOST_ROOT, I believe). You can also just do a ./b2 install to put everything in /usr/local/. 

> I have tried various versions of these 2 cmakelists scripts below (A) and (B)  
> 
> Can anyone point me in the direction of a solution here? 
> 
> 
> A) 
> 
> FIND_PACKAGE( Boost 1.63.0 COMPONENTS program_options REQUIRED )
> INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
> 
> ADD_EXECUTABLE( anyExecutable anyExecutable.cpp )
> 
> TARGET_LINK_LIBRARIES( anyExecutable ${Boost_LIBRARIES} )
> B) 
> INCLUDE_DIRECTORIES(usr/local/boost/include/)
> 
> ADD_EXECUTABLE(  anyExecutable myMain.cpp )
> 
> TARGET_LINK_LIBRARIES( anyExecutable usr/local/boost/lib/ )
> 
> 

version (A) seems closer to what you want to me - but I suspect the error you posted was from option (B). Perhaps try running A again and share the error message(s) you get with that.

-Mike




More information about the CMake mailing list