Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"framework not found" when compiling C++ program on Mac OS-X

I definitely need some help with this problem. I'm trying to fix this since 5 days and as I tried almost every single idea I was able to find on the Internet, I'm going crazy...


When I compile my C++ project with the makefile generated by Cmake the code compile up to 100% but then is unable to link the OGRE framework and exit with an Error 1.

As I was unable to compile using my own project and as the framework my program is unable to locate is the OGRE framework, I tried with the files provided with the Ogre3D setup tutorial to simplify the problem to it's maximum. But the problem and the error remain exactly the sames, and the compilation process stop with:

ld: framework not found OGRE

I tried to copy the Ogre.framework found in OgreSDK/lib/release in the default /Library/Framework of the system and almost everywhere on this computer including the project folder (with modification on the OgreFindFrameWork.cmake file) and particularly all the folder targeted by the OgreFindFrameWork.cmake file, but this error is still here.

I also tried a lot of Cmake modifications or to compile using Xcode, but as it always finish with the same error message, I decided to use the simplest one to illustrate this question. So the following informations are relatives to the OGRETutorialFramework debug project pointed above.

Does anyone can explain me what I need to change to make the linker able to locate a defined framework (I guess that this is not a problem specific to the Ogre framework and I would probably have the same error with another framework) ?

Thank you.


Index of the following parts:
- 1/ The make log
- 2/ The CMakeFile.txt of OGRETutorialFramework
- 3/ The versions of the softs used



- 1/ The make generating and building log

Here is the log of the generating process:

Valkeas-Mac:OGRETutorialFramework root# make
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detected g++ 4.0.1

-- Enabling GCC visibility flags
-- Looking for OGRE...
-- OGRE_PREFIX_WATCH changed.
-- Found Ogre Cthugha (1.7.3)
-- Found OGRE: -framework OGRE
-- Looking for OGRE_Paging...
-- Found OGRE_Paging: -framework OGRE
-- Looking for OGRE_Terrain...
-- Found OGRE_Terrain: /Volumes/Data/OgreSDK/lib/libOgreTerrain.dylib
-- Looking for OGRE_Property...
-- Found OGRE_Property: /Volumes/Data/OgreSDK/lib/libOgreProperty.dylib
-- Looking for OGRE_RTShaderSystem...
-- Found OGRE_RTShaderSystem: /Volumes/Data/OgreSDK/lib/libOgreRTShaderSystem.dylib
-- Looking for OIS...
-- Found OIS: /Volumes/Data/OgreSDK/lib/release/libOIS.a
-- Configuring done
-- Generating done

As you can see the framework is found (-- Found OGRE: -framework OGRE).

And here is the log of the building process:

-- Build files have been written to: /var/root/Desktop/OGRETutorialFramework
Scanning dependencies of target OGRETutorialFramework
[ 50%] Building CXX object CMakeFiles/OGRETutorialFramework.dir/BaseApplication.cpp.o
[100%] Building CXX object CMakeFiles/OGRETutorialFramework.dir/TutorialApplication.cpp.o
Linking CXX executable OGRETutorialFramework.app/Contents/MacOS/OGRETutorialFramework
ld: framework not found OGRE
collect2: ld returned 1 exit status
make[2]: *** [OGRETutorialFramework.app/Contents/MacOS/OGRETutorialFramework] Error 1
make[1]: *** [CMakeFiles/OGRETutorialFramework.dir/all] Error 2
make: *** [all] Error 2
Valkeas-Mac:OGRETutorialFramework root#

And as you can see it is unable to find the OGRE framework (ld: framework not found OGRE)



- 2/ The CMakeFile.txt of OGRETutorialFramework debug project

My Ogre SDK is on my second hard-drive called "Data" so I use the path: /Volumes/Data/OgreSDK

Here is my current CMakeList.txt (the one provided on the Ogre Setting Up tutorial slightly modified to match my folder paths) for the OGRETutorialFramework.

cmake_minimum_required(VERSION 2.6)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
cmake_policy(SET CMP0003 NEW)

set(OGRE_HOME "/Volumes/Data/OgreSDK")
set(Boost_INCLUDE_DIR "${OGRE_HOME}/boost_1_46_1")

# Use relative paths
# This is mostly to reduce path size for command-line limits on windows
if(WIN32)
  # This seems to break Xcode projects so definitely don't enable on Apple builds
  set(CMAKE_USE_RELATIVE_PATHS true)
  set(CMAKE_SUPPRESS_REGENERATION true)
  set(CMAKE_MODULE_PATH "${OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
  set(OGRE_SAMPLES_INCLUDEPATH
      ${OGRE_HOME}/Samples/include)
endif()

# Assign compiler for Mac OS X-based systems
# NOTE: This logic is order-dependent and must occur here because the
# configuration phase of CMake projects will fall into an infinite loop
# if compiler assignments are modified after issuing a project(...) command.
#
if (OGRE_BUILD_PLATFORM_IPHONE)
  # Force gcc <= 4.2 on iPhone
  include(CMakeForceCompiler)
  CMAKE_FORCE_C_COMPILER(gcc-4.2 GNU)
  CMAKE_FORCE_CXX_COMPILER(gcc-4.2 GNU)
elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_IPHONE)
  # Force gcc <= 4.0 on Mac OS X because 4.2 is not supported prior to Mac OS X 10.5
  include(CMakeForceCompiler)
  CMAKE_FORCE_C_COMPILER(gcc-4.0 GNU)
  CMAKE_FORCE_CXX_COMPILER(gcc-4.0 GNU)
endif ()

set(OGRE_PROJECT_NAME
  "OGRETutorialFramework"
)

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/build/bin")

project(${OGRE_PROJECT_NAME})

# Include necessary submodules
# set(OGRE_SOURCE_DIR "/Applications/OgreSDK")
set(OGRE_SOURCE_DIR "/Volumes/Data/OgreSDK")
set(CMAKE_MODULE_PATH 
  "${OGRE_SOURCE_DIR}/CMake"
  "${OGRE_SOURCE_DIR}/CMake/Utils" 
  "${OGRE_SOURCE_DIR}/CMake/Packages"
)
set(OGRE_SAMPLES_INCLUDEPATH
  "${OGRE_SOURCE_DIR}/Samples/Common/include"
)
include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
include(MacroLogFeature)
include(OgreConfigTargets)
include(PreprocessorUtils)
set(OGRE_TEMPLATES_DIR "${OGRE_SOURCE_DIR}/CMake/Templates")


#####################################################################
# Set up the basic build environment
#####################################################################

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

if (NOT APPLE)
  # Create debug libraries with _d postfix
  set(CMAKE_DEBUG_POSTFIX "_d")
endif ()

# Set compiler specific build flags
if (CMAKE_COMPILER_IS_GNUCXX)
  check_cxx_compiler_flag(-msse OGRE_GCC_HAS_SSE)
  if (OGRE_GCC_HAS_SSE)
    add_definitions(-msse)
  endif ()
endif ()
if (MSVC)
  if (CMAKE_BUILD_TOOL STREQUAL "nmake")
    # set variable to state that we are using nmake makefiles
   set(NMAKE TRUE)
  endif ()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
  # Enable intrinsics on MSVC in debug mode
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi")
  if (CMAKE_CL_64)
    # Visual Studio bails out on debug builds in 64bit mode unless
   # this flag is set...
   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
  endif ()
endif ()
if (MINGW)
  add_definitions(-D_WIN32_WINNT=0x0500)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
  # Test for GCC visibility
  include(CheckCXXCompilerFlag)
  check_cxx_compiler_flag(-fvisibility=hidden OGRE_GCC_VISIBILITY)
  if (OGRE_GCC_VISIBILITY)
    # determine gcc version
    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion 
      OUTPUT_VARIABLE OGRE_GCC_VERSION)
    message(STATUS "Detected g++ ${OGRE_GCC_VERSION}")
    message(STATUS "Enabling GCC visibility flags")
    set(OGRE_GCC_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY -fvisibility=hidden")

    # check if we can safely add -fvisibility-inlines-hidden
    string(TOLOWER "${CMAKE_BUILD_TYPE}" OGRE_BUILD_TYPE)
    if (OGRE_BUILD_TYPE STREQUAL "debug" AND OGRE_GCC_VERSION VERSION_LESS "4.2")
      message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
    else ()
      set(OGRE_GCC_VISIBILITY_FLAGS "${OGRE_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
    endif ()
  endif (OGRE_GCC_VISIBILITY)

  # Fix x64 issues on Linux
  if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
    add_definitions(-fPIC)
  endif()  
endif (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)

# determine system endianess
#include(TestBigEndian)
#test_big_endian(OGRE_TEST_BIG_ENDIAN)
set(OGRE_TEST_BIG_ENDIAN FALSE)

# Add OgreMain include path
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include")
include_directories("${OGRE_BINARY_DIR}/include")
if (APPLE)
  if (OGRE_BUILD_PLATFORM_IPHONE)
    include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/iPhone")

    # Set static early for proper dependency detection
    set(OGRE_STATIC TRUE)
  else ()
    include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/OSX")
  endif ()
endif (APPLE)


find_package(OGRE REQUIRED)

if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
  message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
endif()

find_package(OIS REQUIRED)

if(NOT OIS_FOUND)
   message(SEND_ERROR "Failed to find OIS.")
endif()

# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
   if (WIN32 OR APPLE)
      set(Boost_USE_STATIC_LIBS TRUE)
   else ()
      # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
      set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
   endif ()
   if (MINGW)
      # this is probably a bug in CMake: the boost find module tries to look for
      # boost libraries with name libboost_*, but CMake already prefixes library
      # search names with "lib". This is the workaround.
      set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
   endif ()
   set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
   # Components that need linking (NB does not include header-only components like bind)
   set(OGRE_BOOST_COMPONENTS thread date_time)
   find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
   if (NOT Boost_FOUND)
      # Try again with the other type of libs
      set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
      find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
   endif()
   find_package(Boost QUIET)

   # Set up referencing of Boost
   include_directories(${Boost_INCLUDE_DIR})
   add_definitions(-DBOOST_ALL_NO_LIB)
   set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()

set(HDRS
   ./BaseApplication.h
   ./TutorialApplication.h
)

set(SRCS
   ./BaseApplication.cpp
   ./TutorialApplication.cpp
)

include_directories( ${OIS_INCLUDE_DIRS}
   ${OGRE_INCLUDE_DIRS}
   ${OGRE_SAMPLES_INCLUDEPATH}
)

add_executable(${OGRE_PROJECT_NAME} WIN32 ${HDRS} ${SRCS})

set_target_properties(${OGRE_PROJECT_NAME} PROPERTIES DEBUG_POSTFIX _d)

target_link_libraries(${OGRE_PROJECT_NAME} ${OGRE_LIBRARIES} ${OIS_LIBRARIES})

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media)

# post-build copy for win32
if(WIN32 AND NOT MINGW)
   add_custom_command( TARGET ${OGRE_PROJECT_NAME} PRE_BUILD
      COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin )
   add_custom_command( TARGET ${OGRE_PROJECT_NAME} POST_BUILD
      COMMAND copy \"$(TargetPath)\" .\\dist\\bin )
endif(WIN32 AND NOT MINGW)
if(MINGW)
   set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin)
endif(MINGW)

if(WIN32)

   install(TARGETS ${OGRE_PROJECT_NAME}
      RUNTIME DESTINATION bin
      CONFIGURATIONS All)

   install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/Media
      DESTINATION ./
      CONFIGURATIONS Release RelWithDebInfo Debug
   )

   install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
      ${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
      DESTINATION bin
      CONFIGURATIONS Release RelWithDebInfo
   )

   install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins_d.cfg
      ${CMAKE_SOURCE_DIR}/dist/bin/resources_d.cfg
      DESTINATION bin
      CONFIGURATIONS Debug
   )

   install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll
      ${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll
      ${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll
      ${OGRE_PLUGIN_DIR_REL}/OIS.dll
      DESTINATION bin
      CONFIGURATIONS Release RelWithDebInfo
   )

   install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll
      ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll
      ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll
      ${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll
      DESTINATION bin
      CONFIGURATIONS Debug
   )
endif(WIN32)

set_property(TARGET ${OGRE_PROJECT_NAME} PROPERTY MACOSX_BUNDLE TRUE)


- 3/ The versions of the softs used

OSX version: 10.6.7 (Snow Leopard)
Xcode version:3.2.6
GCC version: 4.6 (4.5.3 doesn't compile to 100%, and older versions do not support C++0x which I need) Ogre version: 1.7.3
Cmake version: 2.8.3 or 2.8.4 (I tried both)

like image 364
Valkea Avatar asked Dec 27 '22 19:12

Valkea


1 Answers

I think that you have a problem with duplicated Frameworks in SDK path. You need to move your Frameworks from

/Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks/Frameworks

to

/Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks

and then repair the symbolic link /Library/Frameworks.

I found the solution at Re[2]: не могу въехать в ошибку линковки:

If you are interested: The XCode gets standart library (libstdc++-static.a) depends from the current SDK configuration. But libstdc++-static.a library from MacOS10.5.sdk configuration do not contain _M_insert, _M_extract symbols. For fix this problem we need just switch to the MacOSX10.6.sdk.

BTW!!! If you are use XCode 3.2.6 you will encounter with surprise (bug) from Apple!

The folder: /Developer/SDKs/MacOSX10.6.sdk/Library contain the folder Frameworks with link Frameworks inside. i.e.: /Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks/Frameworks This is wrong.

If you will try to install and use third-party frameworks (for example CG.Frameworks), XCode doesn't find these framework. Because /Developer/SDKs/MacOSX10.6.sdk/Library must contain link to the Frameworks folder BUT not the Framework folder.

Fortunately this problem easy to fix. You need just need rename the Frameworks to (for example) _Framework. Then copy alias Framework from the /Developer/SDKs/MacOSX10.6.sdk/Library/_Frameworks/Frameworks to /Developer/SDKs/MacOSX10.6.sdk/Library/ and then remove renamed folder _Frameworks forewer.

I repeat again this applies only for XCode 3.2.6

like image 126
Ignat Kolesnichenko Avatar answered Dec 31 '22 15:12

Ignat Kolesnichenko