Search code examples
linuxqtcmakeqt5openscenegraph

cmake in Qt cannot find third-party libraries while cmake from command line can


I'm using Qt (5.5.1) with OpenSceneGraph (OSG-3.4.0) library. I have a basic "HelloWorld" project that compiles and works from Qt on another machine on Windows 7. But when I try to compile the same project on Linux (Lubuntu-14.04), the CMake within the Qt cannot find the OSG libraries. The strangest thing is that when I run cmake from command line, all the libraries are found - no problem.

So, that's how I search for libraries within my CMake project file:

# ...
find_package(OpenSceneGraph REQUIRED COMPONENTS osgDB osgGA osgUtil osgViewer)

include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
#...

target_link_libraries( ${PROJECT_NAME}
    ${OPENSCENEGRAPH_LIBRARIES}
    )

I also include some Qt libraries, and they are found with no problem.

When I check the location of CMake within the Qt (in Manage kits... menu), it shows me the same path as when I run which cmake from a command line. So, the cmake executable is the same, and is located at /usr/bin/. My cmake --version is 2.8.12.2.

My .zshrc contains all the paths for the installed OSG libraries (as it is described in OSG installation manual):

export OPENTHREADS_INC_DIR="/usr/local/include"
export OPENTHREADS_LIB_DIR="/usr/local/lib64:/usr/local/lib"
export PATH="$OPENTHREADS_LIB_DIR:$PATH"
export LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/lib:$LD_LIBRARY_PATH"
export OSG_FILE_PATH="/usr/local/OpenSceneGraph/data:/usr/local/OpenSceneGraph/data/Images"

I found a temporal solution for my problem:

  • first I run cmake from a command line;
  • then I give Qt the location of just build folder.

This way everything works.

However, I want to know where is the problem so that I could run cmake from Qt; it's been buzzing me for several days, and I ran out of ideas what is wrong with my setup. Any hints and suggestions are appreciated.

UPD: here is the error message that I get when try to run CMake from Qt:

-- Could NOT find osgDB (missing:  OSGDB_LIBRARY) 
-- Could NOT find osgGA (missing:  OSGGA_LIBRARY) 
-- Could NOT find osgUtil (missing:  OSGUTIL_LIBRARY) 
-- Could NOT find osgViewer (missing:  OSGVIEWER_LIBRARY) 
-- Could NOT find osg (missing:  OSG_LIBRARY) 
-- Could NOT find OpenThreads (missing:  OPENTHREADS_LIBRARY) 
CMake Error at /usr/share/cmake-2.8/Modules /FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find OpenSceneGraph (missing: OPENSCENEGRAPH_LIBRARIES
OSGDB_FOUND OSGGA_FOUND OSGUTIL_FOUND OSGVIEWER_FOUND OSG_FOUND
OPENTHREADS_FOUND) (found version "3.4.0")

Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake:187 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:19 (find_package)

-- Configuring incomplete, errors occurred!

The OSG library files are installed in:

/usr/local/bin
/usr/local/include
/usr/local/lib64

UPD2: as user1034749 suggested, it seems there is a problem with environment variables. When I launch QtCreator from a command line - everything works; if I launch it from a menu, then it cannot find the libraries.


Solution

  • Unfortunately I could not find how to fix the problem with the given setup. I discovered my Qt was not installed correctly on my Linux machine. To fix the problem: I had to remove all the Qt versions from my Linux machine and then re-install a new Qt version.