尝试与osgText和freetype链接时出错

时间:2015-04-07 00:47:10

标签: linux hyperlink freetype openscenegraph

我已经检查过几十个关于此的网页和配置。 我很绝望,因为我真的需要很快使用这个功能。

这些是我的设置:

  • 语言:C ++
  • 库:OpenSceneGraph(OSG)v3.2.0
  • OS:Xubuntu 14.04(在VMWare Player虚拟机上)

我正在编写一本关于在OSG上使用Text的书#34; OpenSceneGraph 3.0 - 初学者指南",第297-299页的例子,这需要一个额外的插件,freetype (http://www.freetype.org/),已安装。

示例正确编译。 我想我有所有必需的包含文件和库。

问题出现在链接阶段。它总是给我这个错误:

/usr/bin/ld: CMakeFiles/osg_demos.dir/osg_demos.cpp.o: undefined reference to symbol '_ZN7osgText12readFontFileERKSsPKN5osgDB7OptionsE'
//usr/lib/libosgText.so.99: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [osg_demos] Error 1
make[1]: *** [CMakeFiles/osg_demos.dir/all] Error 2
make: *** [all] Error 2

我检查过我有文件:

  • " /usr/lib/libosgText.so.99"这是实际lib文件的链接: " libosgText.so.3.2.0"
  • " /usr/lib/osgPlugins-3.2.0/osgdb_freetype.so" osgText库的外部依赖。

我没有想法了。 :(
有人能帮助我吗?

我的问题在此处停止,但如果您想查看我的文件,请在下方找到。

负责此问题的代码:

osgText::Text* createText( const osg::Vec3& pos, 
          const std::string& content, float size ) {
  osg::ref_ptr<osgText::Font> g_font = osgText::readFontFile("arial.ttf");
  osg::ref_ptr<osgText::Text> text = new osgText::Text;
  text->setFont( g_font.get() );
  text->setCharacterSize( size );
  text->setAxisAlignment( osgText::TextBase::XY_PLANE );
  text->setPosition( pos );
  text->setText( content );
  return text.release();
}

除了我在项目中已经需要的所有其他文件外,这些是我正在使用的Include文件,这些文件特定于osgText操作:

#include <osg/Camera>
#include <osgText/TextBase>
#include <osgText/Font>
#include <osgText/Text>

这是我的&#34; CMakeLists.txt&#34;文件:

cmake_minimum_required( VERSION 2.6 )
project( OSG_DEMOS )

find_package( OpenThreads )
find_package( osg )
find_package( osgDB )
find_package( osgGA )
find_package( osgUtil )
find_package( osgViewer )
find_package( osgText )         # Needed for demo: writeText()
find_package( osgShadow )       # Needed for demo: writeText()
find_package( osgParticle )     # Needed for demo: writeText()
find_package( osgFX )           # Needed for demo: writeText()
find_package(PCL 1.6 COMPONENTS)

set(CMAKE_CXX_FLAGS "-g -Wno-deprecated")

macro( config_project PROJNAME LIBNAME )
    include_directories( ${${LIBNAME}_INCLUDE_DIR} )
    target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARIES} )
endmacro()

add_executable(osg_demos osg_demos.cpp)

config_project(osg_demos OPENTHREADS )
config_project(osg_demos OSG )
config_project(osg_demos OSGDB )
config_project(osg_demos OSGGA )
config_project(osg_demos OSGUTIL )
config_project(osg_demos OSGVIEWER )
config_project(osg_demos osgText )
config_project(osg_demos osgShadow )
config_project(osg_demos osgParticle )
config_project(osg_demos osgFX )

1 个答案:

答案 0 :(得分:0)

问题出在“CMakeLists.txt”文件中。 显然,config_project宏需要所有大写字母。我不完全理解为什么。 为了使项目链接正确,我在该文件的最后四行切换为对库名称的引用大写,如:

  • config_project(osg_demos OSGTEXT)

而不是:

  • config_project(osg_demos osgText)

因为这个真是个噩梦......