1

I created a XCode project with CMake including the Boost 1.55 library and I got into a problem I can't solve by myself.

The include

#include "boost/filesystem.hpp" 

just works in EIATHelper.cxx, but not in header EIATHelper.h. In the header it says "file not found" and consequently the build fails. But still the include seems to work, because Xcode doesn't bitch about the used objects defined in "the missing" filesystem.hpp.

Important! When I put the include and all my code into the .cxx files everything works (build/execute).

I added a screenshot who may helps to understand the problem better. (of course I didn't use the double #include):

xcode error message

The project is completely created with CMake.

CMakeLists.txt from subfolder header:

project(${PROJECT_NAME})

add_library(helper
${PROJECT_NAME}Helper.h
${PROJECT_NAME}Helper.cxx
)

set(BOOST_ROOT /Users/name/Libs/Boost/bin)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)

set(BOOST_INCLUDEDIR /Users/name/Libs/Boost/bin/include)
set(BOOST_LIBRARYDIR /Users/name/Libs/Boost/bin/lib)


find_package(Boost COMPONENTS
  system
  filesystem
  log
  log_setup
)

include_directories(${Boost_INCLUDE_DIRS})

if(NOT Boost_FOUND)
  message("Boost was NOT found")
endif()


target_link_libraries(helper ${BOOST_LIBRARIES})

Edit: I created a Eclipse CDT4 Project with CMake, same problem here. Header filsystem.hpp not found in the EIATHelper.h. So I guess something has to be wrong with my project settings, regardless of the IDE.

7
  • What is "/Users/name/Libs/Boost/bin/include"? Are you sure the Boost headers are there? Commented May 20, 2014 at 11:44
  • Yeah, I am sure. Like I said, the in #include and all code with boost is working as long as I put the code inside the EIATHelper.cxx file! After I moved the include and the prototypes of my methods to the EIATHelpber.h, it said, "boost/filesystem.hpp" is not found but still he finds the defined types inside filesystem.hpp... so maybe its just an issue with xcode? Commented May 20, 2014 at 11:56
  • Note that the compiler does not compile header files directly. They are compiled indirectly through the source files that pull them in via #include. Hence, if you see a compile error in a header file, you first need to find out which source file generated the error. Which .cxx files do include the EIATHelper.h in your project? You need to make sure that all of them have the Boost directories in their include path. Commented May 20, 2014 at 12:13
  • EIATHelper.cxx #includes EIATHelper.h ------- EIATHelper.h #includes "boost/filesystem.hpp" ------- Commented May 20, 2014 at 12:38
  • Just a guess, is BOOST_INCLUDEDIR set correctly? The "bin" in the path seems strange. Commented May 20, 2014 at 13:05

1 Answer 1

1

just works in EIATHelper.cxx, but not in header EIATHelper.h

No, it's not. EIATHelper.cxx includes EIATHelper.h, so "header not found" error appears first in EIATHelper.h and is kind of a fatal error - compilation stops without processing EIATHelper.cxx (hence without reporting any errors in EIATHelper.cxx).

I'm pretty sure that error is in finding boost libraries. Some notes:

  • BOOST_INCLUDEDIR and BOOST_LIBRARYDIR is a hints. If you set BOOST_ROOT and libraries is in a standard paths (lib and include) you don't need them.
  • Boost is mandatory for EIATHelper.{h,cxx} it's better to use REQUIRED suboption (you don't need to check Boost_FOUND):

    find_package(Boost REQUIRED system filesystem log log_setup)

  • CMake variables is case-sensitive, use Boost_LIBRARIES instead of BOOST_LIBRARIES
  • Do not hardcode BOOST_ROOT variable, it's not user friendly. At least do something like that:
if(NOT BOOST_ROOT)
  set(BOOST_ROOT /some/default/path/to/boost)
endif()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.