user3655592
user3655592

Reputation: 11

XCode #include bug - not found in header file but in cxx

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.

Upvotes: 1

Views: 431

Answers (1)

user2288008
user2288008

Reputation:

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()

Upvotes: 1

Related Questions