使用Macports的Mac上的OpenSceneGraph链接器错误

时间:2015-11-27 01:42:33

标签: c++ macos makefile macports openscenegraph

我在使用OpenSceneGraph项目在Mac上正确链接时遇到问题。我通过macports安装它,我已经得到了osgviewer和其他osg程序,这意味着它以某种方式编译和链接。代码是一个更大的项目的一部分,但是我将OSG代码分解为单独的代码以隔离我的问题。我首先想到这是一个CMake问题,所以我创建了一个Makefile来尝试并在那里隔离。这没有任何区别。

以下是示例代码。

// OpenSceneGraph Libraries
#include <osg/Geode>
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osgUtil/Optimizer>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/Simplifier>
#include <osg/Node>
#include <osg/Texture1D>
#include <osg/Texture2D>
#include <osg/TexGen>
#include <osg/Material>
#include <osgViewer/Viewer>
#include <osgDB/Registry>
#include <osgDB/WriteFile>
#include <osgDB/ReadFile>
#include <osgSim/Version>
#include <osgFX/Version>
#include <osgTerrain/Version>
#include <osgVolume/Version>



// C++ Libraries 
#include <iostream>
#include <string>


/**
 * @brief Main Application
*/
int main( int argc, char* argv[] )
{

    // Define Write Options
    osgDB::Options* write_options = new osgDB::Options("WriteImageHint=IncludeData Compressor=zlib");

    // Create the Root Nodes
    osg::ref_ptr<osg::Group> root_node(new osg::Group());



    // Write the Node File
    osgDB::writeNodeFile( *root_node.get(),
                           "output.osgb",
                           write_options );

    // Return
    return 0;
}

这是Makefile代码。我添加的方式超出了需要而没有效果。

OSG_LIBS=-lOpenThreads -losgDB -losg -losgUtil -losgTerrain

LIBS=-L/opt/local/lib $(OSG_LIBS)
INCL=-I/opt/local/include

CPP=clang++

foo: foo.cpp
    $(CPP) foo.cpp $(LIBS) $(INCL)

这是特定命令的VERBOSE = 1的make输出。

$ make VERBOSE=1
clang++ foo.cpp -L/opt/local/lib -lOpenThreads -losgDB -losg -losgUtil -losgTerrain -I/opt/local/include
Undefined symbols for architecture x86_64:
  "osgDB::writeNodeFile(osg::Node const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, osgDB::Options const*)", referenced from:
  _main in foo-2c45f6.o
  "osgDB::Options::parsePluginStringData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char, char)", referenced from:
  osgDB::Options::Options(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in foo-2c45f6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [foo] Error 1

我已针对共享库运行otool和其他应用程序,以尝试查找未定义引用的位置。我知道当我运行nm时,这两种方法的符号都在libosgDB.dylib中,但链接却不起作用。

我开始从源代码编译OpenSceneGraph,但这也是自己创建编译错误。我前面还有很长的路要走。非常感谢你的时间。

更新

观察

  • 在编译器行上重新排序库不起作用。

1 个答案:

答案 0 :(得分:1)

嗯,我可以重现你的问题。似乎MacPorts的OpenSceneGraph端口安装的libosgDB.dylib链接到libstdc ++:

$ otool -L /opt/local/lib/libosgDB.dylib
/opt/local/lib/libosgDB.dylib:
    /opt/local/lib/libosgDB.100.dylib (compatibility version 100.0.0, current version 3.2.1)
    /opt/local/lib/libosgUtil.100.dylib (compatibility version 100.0.0, current version 3.2.1)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 157.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)
    /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    /opt/local/lib/libosg.100.dylib (compatibility version 100.0.0, current version 3.2.1)
    /opt/local/lib/libOpenThreads.20.dylib (compatibility version 20.0.0, current version 3.2.1)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1255.1.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 728.4.0)

我认为这是OpenSceneGraph端口的错误。请提交一张票以解决这个问题。同时,在编译器命令行中使用-stdlib=libstdc++来获取链接示例。请注意,这意味着您无法使用C ++ 11功能。