【问题标题】:Google Earth C ++ API Library Errors on UbuntuUbuntu 上的 Google 地球 C++ API 库错误
【发布时间】:2012-06-18 17:54:53
【问题描述】:

我是这个论坛的新手,但在尝试寻找解决此问题的方法时,我已经看过几次了。我正在尝试使用我为 Ubuntu (libkml-dev_1.2.0-1ubuntu6_amd64) 找到的 C++ API 库生成要在 Google 地球中使用的 KML 文件。我使用命令 sudo apt-get install libkml-dev 安装了软件包,成功返回。之后,我使用命令行终端导航到示例文件夹,尝试使用命令 g++ helloworld.cc -o helloworld 执行程序“helloworld.cc”,但随后出现大量错误(主要声称 kmldom 是一个未定义的引用)。抱歉,我想附上文本文件,但不知道怎么做,所以我在下面提供了一个错误示例。我整周都在搜索,确保头文件确实包含在下载中,甚至就问题联系了谷歌地球开发人员(他们回答说他们与此无关,并重定向所有关于StackOverflow)。

有谁知道是什么导致了这个问题,我可以做些什么来解决这个问题,以便我继续前进?


/tmp/cc5u2JyV.o:在函数HelloKml(bool)': helloworld.cc:(.text+0x17): undefined reference to kmldom::KmlFactory::GetFactory()' helloworld.cc:(.text+0x27): 未定义引用kmldom::KmlFactory::CreateCoordinates() const' helloworld.cc:(.text+0x328): undefined reference to kmldom::AsPoint(boost::intrusive_ptrkmldom::Element)' /tmp/cc5u2JyV.o:在函数boost::intrusive_ptr<kmldom::Coordinates>::intrusive_ptr(kmldom::Coordinates*, bool)': helloworld.cc:(.text._ZN5boost13intrusive_ptrIN6kmldom11CoordinatesEEC2EPS2_b[_ZN5boost13intrusive_ptrIN6kmldom11CoordinatesEEC5EPS2_b]+0x3d): undefined reference to kmlbase::intrusive_ptr_add_ref(kmlbase::Referent*)' /tmp/cc5u2JyV.o:在函数boost::intrusive_ptr<kmldom::Coordinates>::~intrusive_ptr()': helloworld.cc:(.text._ZN5boost13intrusive_ptrIN6kmldom11CoordinatesEED2Ev[_ZN5boost13intrusive_ptrIN6kmldom11CoordinatesEED5Ev]+0x23): undefined reference to kmlbase::intrusive_ptr_release(kmlbase::Referent*)' /tmp/cc5u2JyV.o:在函数boost::intrusive_ptr<kmldom::Geometry>::intrusive_ptr(boost::intrusive_ptr<kmldom::Geometry> const&)': helloworld.cc:(.text._ZN5boost13intrusive_ptrIN6kmldom8GeometryEEC2ERKS3_[_ZN5boost13intrusive_ptrIN6kmldom8GeometryEEC5ERKS3_]+0x35): undefined reference to kmlbase::intrusive_ptr_add_ref(kmlbase::Referent*)' collect2: ld 返回 1 个退出状态

【问题讨论】:

    标签: c++ linux api terminal google-earth


    【解决方案1】:

    当你编译使用库的应用程序时,你需要在你的应用程序编译时链接它。所以,尝试使用这个参数:

    要指定一个目录来搜索你的库,请使用 -L:

    -L/data[...]/lib

    要指定实际的库名称,请使用 -l:

    -labc(链接 abc.a 或 abc.so)

    要指定搜索包含文件的目录,请使用 -I:

    -I/data[...]/lib

    【讨论】:

    【解决方案2】:

    我找到了解决方案。问题是您错误地链接了 libkml。您应该找到头文件和库文件 (*.so) 的路径。我在这里找到了它们:

    /usr/include/kml/(包括带有标题的 dit),
    /usr/lib/x86_64-linux-gnu/(库目录)。

    我在一个项目中使用 CMake 和 CMakeLists.txt。使用 libkml 可能如下所示:

    `cmake_minimum_required (VERSION 3.2)
    # Set language standard
    set(CMAKE_CXX_STANDARD "11")
    project (test_proj)
    
    add_definitions(-std=c++11)
    
    # Set default build type to RelWithDebInfo if not specified
    if (NOT CMAKE_BUILD_TYPE)
        message (STATUS "Default CMAKE_BUILD_TYPE not set using Release with Debug Info")
        set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE
            STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel"
            FORCE)
    endif()
    
    # linking boost library
    find_package(Boost COMPONENTS system filesystem thread REQUIRED)
    if(NOT Boost_FOUND)
        message(SEND_ERROR "Failed to find boost.")
        return()
    else()
        include_directories(${Boost_INCLUDE_DIRS})
    endif()
    
    add_executable(test_proj main.cpp)
    
    set (LibKML_INCLUDE_DIRS /usr/include/kml/)
    set (LibKML_LIBRARIES /usr/lib/x86_64-linux-gnu/libkmlbase.so /usr/lib/x86_64-linux-gnu/libkmlconvenience.so /usr/lib/x86_64-linux-gnu/libkmldom.so /usr/lib/x86_64-linux-gnu/libkmlengine.so /usr/lib/x86_64-linux-gnu/libkmlregionator.so /usr/lib/x86_64-linux-gnu/libkmlxsd.so)
    
    message("LibKML is at: ${LibKML_INCLUDE_DIRS} and ${LibKML_LIBRARIES}")
    message("Boost is at: ${Boost_INCLUDE_DIRS} and ${Boost_LIBRARIES}")
    
    target_include_directories(test_proj 
    PUBLIC 
    ${LibKML_INCLUDE_DIRS} 
    ${Boost_INCLUDE_DIRS} ) 
    
    target_link_libraries(test_proj 
    PUBLIC
    ${LibKML_LIBRARIES} ${Boost_LIBRARIES})
    
    install(TARGETS test_proj EXPORT test_proj_export)
    export(EXPORT test_proj_export FILE cmake/test_proj-targets.cmake)`
    

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多