铛链接报告"找不到符号&QUOT ;,尽管“纳米-m”透露,该名在正在对链接库的存在 [英] Clang linker reports "symbol not found", despite 'nm -m' revealing that the name exists in a library that is being linked against

查看:152
本文介绍了铛链接报告"找不到符号&QUOT ;,尽管“纳米-m”透露,该名在正在对链接库的存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X(铛),在联动阶段,一个符号(的boost ::文件系统:: portable_posix_name )在我的code未被发现。这里是一个包含我在我的code调用函数的简要code片断:

 如果(的boost ::文件系统:: is_directory(settings.parent_path())
 &功放;&安培;提高::文件系统:: portable_posix_name(settings.filename()。字符串()))
{...}

(请让我知道,如果需要我的code段更多的上下文。)

链接器命令行中,当程序编译和链接,使用包含以下内容:

-L /用户/管理员/ boost_1_54_0 / lib目录-lboost_filesystem

...并指出路径和文件名(包括 libboost_filesystem.a libboost_filesystem.dylib )的存在的路径指示。

链接器无法找到Boost功能的boost ::文件系统:: portable_posix_name(标准::字符串常量和放大器;)

适用于建筑x86_64的未定义符号:
  的boost ::文件系统:: portable_posix_name(STD :: __ 1 :: basic_string的<焦炭,性病:: __ 1 :: char_traits<焦炭>中的std :: __ 1 ::分配器<焦炭>>常量和放大器;)

不过,我看到这个功能适用于 .A 名为.dylib 有问题的文件存在:

纳米-m ./libboost_filesystem.a 显示 00000000000090f0(__TEXT,__文本)外部__ZN5boost10filesystem19portable_posix_nameERKSs ,并运行错位的函数名 __ ZN5boost10filesystem19portable_posix_nameERKSs 通过 demangler 线显示:

_boost ::文件系统:: portable_posix_name(标准::字符串常量和放大器;)

...我相信强调,precedes的名字是正确的,因为这也有发现其他功能有preceding下划线。

(即名为.dylib 文件还包含同样的重整字符串)。

我已经证实,无论是 .A 名为.dylib 文件是正确的体系结构: otool -hv ./libboost_filesystem.a 显示 x86_64的'通和通(同上,并在名为.dylib )。

只是要确保库竟是被人发现和链接,我改变了编译命令行库的名称如下:

-L /用户/管理员/ boost_1_54_0 / lib目录-lboost_filesystemm

(注意双毫米在文件名末尾),只是为了确认一个库未找到返回错误,它是: LD:库找不到-lboost_filesystemm 。我还证实,在 libboost_filesystem.a 名为.dylib 文件的文件系统中唯一出现在那些给定升压目录树(一个在 / lib目录目录中,大小相同的另一个,并在 / bin中几乎相同的创建日期/时间.V2 子目录);同时,改变了 -L /用户/管理员/ boost_1_54_0 / lib目录线,使其垃圾引起 LD:库找不到-lboost_filesystem 出现错误。

奇怪的是,当我用grep的纳米-m 输出的presence的boost ::文件系统:: is_directory 没有结果出现的为后者函数库中的符号表,即使没有的没有的链接此功能错误。这非常似乎倒退到我(任何的的出现在图书馆链接精细的功能,但的功能不的出现在库给出了一个链接错误?) - 但这个问题是另一天(也许,实际上将是这个函数未定义的符号错误,但它没有被显示,由于第一个未定义的符号错误)。

我的问题是:这是为什么找不到符号,尽管事实上,正确的库,以正确的体系结构,具有正确的外部符号,被链接?


在回应@塞巴斯蒂安的回答,我在这里粘贴为链接器的完整的命令行。该命令行是通过Qt的(这是一个Qt项目)。

创建

请注意出现的 -lboost_filesystem 参数的之后的所有目标文件都已经上市。


  

/Applications/X$c$c.app/Contents/Developer/Toolchains/X$c$cDefault.xctoolchain/usr/bin/clang++
  -headerpad_max_install_names -Wl,-syslibroot,/Applications/X$c$c.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
  -stdlib = ++的libc -mmacosx版本分钟= 10.7 -o NewGene.app/Contents/MacOS/NewGene main.o中newgenemainwindow.o
  newgenecreateoutput.o newgeneselectvariables.o
  newgenevariablesummary.o newgenetabwidget.o newgenevariablegroup.o
  newgenevariables.o newgenevariablegroupsscrollarea.o
  newgenevariablestoolboxwrapper.o newgenevariablestoolbox.o
  newgenevariablesummaryscrollarea.o newgenevariablesummarygroup.o
  kadcolumnselectionbox.o timerangebox.o newgenewidget.o
  uisettingsmanager.o uimodelmanager.o uidocumentmanager.o
  uistatusmanager.o globals.o uimanager.o
  settingchangeresponseind​​icator.o settingchangerequestindicator.o
  settingchangeindicator.o projectsettingchangeindicator.o
  globalsettingchangeindicator.o settingchangeresponseitem.o
  settingchangerequestitem.o settingchangeitem.o
  projectsettingchangeitem.o globalsettingchangeitem.o
  globalsettingchangerequestindicator.o
  globalsettingchangeresponseind​​icator.o
  globalsettingchangerequestitem.o globalsettingchangeresponseitem.o
  projectsettingchangerequestindicator.o
  projectsettingchangeresponseind​​icator.o
  projectsettingchangerequestitem.o projectsettingchangeresponseitem.o
  modelchangeresponse.o modelchangerequest.o modelchangeindicator.o
  modelchangeresponseitem.o modelchangerequestitem.o modelchangeitem.o
  uiprojectmanager.o newgenefilenames.o uiloggingmanager.o
  newgeneapplication.o uiallsettings.o uisetting.o uimessager.o
  uiinputproject.o uioutputproject.o uiinputmodel.o uioutputmodel.o
  uiallprojectsettings.o uimodel.o uiproject.o uiinputprojectsettings.o
  uioutputprojectsettings.o uiallglobalsettings.o
  uiallglobalsettings_list.o uiinputprojectsettings_list.o
  uioutputprojectsettings_list.o uithreadmanager.o uitriggermanager.o
  uimodelsettings.o uiinputmodelsettings.o uioutputmodelsettings.o
  eventloopthreadmanager.o workqueuemanager.o
  outputprojectworkqueue_base.o inputprojectworkqueue_base.o
  inputprojectworkqueue.o outputprojectworkqueue.o
  inputmodelworkqueue_base.o outputmodelworkqueue_base.o
  inputmodelworkqueue.o outputmodelworkqueue.o
  inputprojectsettingsworkqueue_base.o
  outputprojectsettingsworkqueue_base.o globalsettingsworkqueue_base.o
  inputmodelsettingsworkqueue_base.o outputmodelsettingsworkqueue_base.o
  globalsettingsworkqueue.o inputmodelsettingsworkqueue.o
  outputmodelsettingsworkqueue.o inputprojectsettingsworkqueue.o
  outputprojectsettingsworkqueue.o uiuidatamanager.o uiuiactionmanager.o
  uimodelactionmanager.o uiprojectmanagerworkqueue_base.o
  uiprojectmanagerworkqueue.o uiwidgetdatarefresh.o
  uimessagersingleshot.o modelworkqueue.o uiaction.o
  variablegroupsetmemberselectionchange.o kadwidgetsscrollarea.o
  kadspinbox.o kadcountchange.o generateoutput.o newgenedatetimewidget.o
  timerangechange.o newgenegenerateoutput.o generaloptions.o
  qrc_NewGeneResources.o moc_newgenemainwindow.o
  moc_newgenecreateoutput.o moc_newgeneselectvariables.o
  moc_newgenevariablesummary.o moc_newgenetabwidget.o
  moc_newgenevariablegroup.o moc_newgenevariables.o
  moc_newgenevariablegroupsscrollarea.o
  moc_newgenevariablestoolboxwrapper.o moc_newgenevariablestoolbox.o
  moc_newgenevariablesummaryscrollarea.o
  moc_newgenevariablesummarygroup.o moc_kadcolumnselectionbox.o
  moc_timerangebox.o moc_uisettingsmanager.o moc_uimodelmanager.o
  moc_uidocumentmanager.o moc_uistatusmanager.o
  moc_globalsettingchangerequestindicator.o
  moc_globalsettingchangeresponseind​​icator.o
  moc_globalsettingchangerequestitem.o
  moc_globalsettingchangeresponseitem.o
  moc_projectsettingchangerequestindicator.o
  moc_projectsettingchangeresponseind​​icator.o
  moc_projectsettingchangerequestitem.o
  moc_projectsettingchangeresponseitem.o moc_modelchangeresponse.o
  moc_modelchangerequest.o moc_modelchangeindicator.o
  moc_modelchangeresponseitem.o moc_modelchangerequestitem.o
  moc_modelchangeitem.o moc_uiprojectmanager.o moc_uiloggingmanager.o
  moc_newgeneapplication.o moc_uimessager.o moc_uiinputproject.o
  moc_uioutputproject.o moc_uiinputmodel.o moc_uioutputmodel.o
  moc_uiinputprojectsettings.o moc_uioutputprojectsettings.o
  moc_uiallglobalsettings.o moc_uithreadmanager.o moc_uitriggermanager.o
  moc_uiinputmodelsettings.o moc_uioutputmodelsettings.o
  moc_workqueuemanager.o moc_uiuidatamanager.o moc_uiuiactionmanager.o
  moc_uimodelactionmanager.o moc_kadwidgetsscrollarea.o moc_kadspinbox.o
  moc_newgenedatetimewidget.o moc_newgenegenerateoutput.o结果
  -F /用户/管理员/ QT / 5.1.1 / clang_64 / lib目录-L/Users/administrator/newgene/NewGeneUI/NewGene/../../NewGeneBackEnd/OSX/NewGene/DerivedData/NewGene/Build/Products/Debug
  -lNewGene -L /用户/管理员/ boost_1_54_0 / lib目录-lboost_filesystem -framework QtWidgets -framework QtGui -framework QtCore -framework的OpenGL -framework AGL



解决方案

一个赠品是的std :: __ 1 在链接的警告消息。这是的libc ++ 内部创建标准库类,如字符串专门强制链接错误,因为默认情况下,在OS X包括C ++库与使用不兼容的的libc ++

更多细节,有链接,在一个给定的问题,我贴在试图回答的这个的问题:<一href=\"http://stackoverflow.com/questions/20614205/boost-why-is-toolset-listed-in-user-config-jam-not-available-to-b2\">Boost:为什么工具集〜/用户config.jam中不可上市./b2?

答案是重建在OS X增强,同时指定作为编译器和的libc ++ 作为标准C ++库。(同样,见链接的问题的详细信息。)

On OS X (clang), during linkage stage, a symbol (boost::filesystem::portable_posix_name) in my code is not being found. Here is a brief code snippet that contains the function I am calling in my code:

if (boost::filesystem::is_directory(settings.parent_path())
 && boost::filesystem::portable_posix_name(settings.filename().string()))
{ ... }

(Please let me know if more context in my code snippet is required.)

The linker command line, used when the program compiles and links, contains the following:

-L/Users/administrator/boost_1_54_0/lib -lboost_filesystem

... And the path and filename indicated (both libboost_filesystem.a and libboost_filesystem.dylib) exist at the path indicated.

The linker cannot find the Boost function boost::filesystem::portable_posix_name(std::string const &):

Undefined symbols for architecture x86_64: "boost::filesystem::portable_posix_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)"

However, I do see that this function exists in both the .a and .dylib files in question:

nm -m ./libboost_filesystem.a reveals 00000000000090f0 (__TEXT,__text) external __ZN5boost10filesystem19portable_posix_nameERKSs, and running the mangled function name __ZN5boost10filesystem19portable_posix_nameERKSs line through the demangler reveals:

_boost::filesystem::portable_posix_name(std::string const&)

... I trust that the underscore that precedes the name is correct, because other functions that ARE found also have the preceding underscore.

(The .dylib file also contains the same mangled string).

I have confirmed that the architecture of both the .a and .dylib files are correct: otool -hv ./libboost_filesystem.a shows 'x86_64' through-and-through (and ditto for the .dylib).

Just to be sure the library was actually being found and linked, I changed the name of the library in the compile command line as follows:

-L/Users/administrator/boost_1_54_0/lib -lboost_filesystemm

(notice the double mm at the end of the filename), just to confirm that that a "library not found" error was returned, and it was: ld: library not found for -lboost_filesystemm. I have also confirmed that the only occurrences in the file system of the libboost_filesystem.a and .dylib files are those within the given Boost directory tree (one in the /lib directory, and another one of the same size and almost identical creation date/time in the /bin.v2 subdirectory); also, changing the -L/Users/administrator/boost_1_54_0/lib line to make it junk causes a ld: library not found for -lboost_filesystem error to appear.

Oddly, when I grep the nm -m output for the presence of boost::filesystem::is_directory, no results appear in the symbol table for the library for the latter function, even though there is no linker error for this function. This seems awfully backwards to me (the function that does not appear in the library links fine, but the function that does appear in the library gives a linker error?) - but that question is for another day (and, perhaps, there actually would be an undefined symbol error for this function, but it's not being shown due to the first undefined symbol error).

My question is: Why is this symbol not found, despite the fact that the correct library, with the correct architecture, with the correct external symbol, is being linked?


In response to @Sebastian's answer, I am here pasting the full command line for the linker. This command line is created by Qt (this is a Qt project).

Note that the -lboost_filesystem argument appears after all object files have been listed.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -stdlib=libc++ -mmacosx-version-min=10.7 -o NewGene.app/Contents/MacOS/NewGene main.o newgenemainwindow.o newgenecreateoutput.o newgeneselectvariables.o newgenevariablesummary.o newgenetabwidget.o newgenevariablegroup.o newgenevariables.o newgenevariablegroupsscrollarea.o newgenevariablestoolboxwrapper.o newgenevariablestoolbox.o newgenevariablesummaryscrollarea.o newgenevariablesummarygroup.o kadcolumnselectionbox.o timerangebox.o newgenewidget.o uisettingsmanager.o uimodelmanager.o uidocumentmanager.o uistatusmanager.o globals.o uimanager.o settingchangeresponseindicator.o settingchangerequestindicator.o settingchangeindicator.o projectsettingchangeindicator.o globalsettingchangeindicator.o settingchangeresponseitem.o settingchangerequestitem.o settingchangeitem.o projectsettingchangeitem.o globalsettingchangeitem.o globalsettingchangerequestindicator.o globalsettingchangeresponseindicator.o globalsettingchangerequestitem.o globalsettingchangeresponseitem.o projectsettingchangerequestindicator.o projectsettingchangeresponseindicator.o projectsettingchangerequestitem.o projectsettingchangeresponseitem.o modelchangeresponse.o modelchangerequest.o modelchangeindicator.o modelchangeresponseitem.o modelchangerequestitem.o modelchangeitem.o uiprojectmanager.o newgenefilenames.o uiloggingmanager.o newgeneapplication.o uiallsettings.o uisetting.o uimessager.o uiinputproject.o uioutputproject.o uiinputmodel.o uioutputmodel.o uiallprojectsettings.o uimodel.o uiproject.o uiinputprojectsettings.o uioutputprojectsettings.o uiallglobalsettings.o uiallglobalsettings_list.o uiinputprojectsettings_list.o uioutputprojectsettings_list.o uithreadmanager.o uitriggermanager.o uimodelsettings.o uiinputmodelsettings.o uioutputmodelsettings.o eventloopthreadmanager.o workqueuemanager.o outputprojectworkqueue_base.o inputprojectworkqueue_base.o inputprojectworkqueue.o outputprojectworkqueue.o inputmodelworkqueue_base.o outputmodelworkqueue_base.o inputmodelworkqueue.o outputmodelworkqueue.o inputprojectsettingsworkqueue_base.o outputprojectsettingsworkqueue_base.o globalsettingsworkqueue_base.o inputmodelsettingsworkqueue_base.o outputmodelsettingsworkqueue_base.o globalsettingsworkqueue.o inputmodelsettingsworkqueue.o outputmodelsettingsworkqueue.o inputprojectsettingsworkqueue.o outputprojectsettingsworkqueue.o uiuidatamanager.o uiuiactionmanager.o uimodelactionmanager.o uiprojectmanagerworkqueue_base.o uiprojectmanagerworkqueue.o uiwidgetdatarefresh.o uimessagersingleshot.o modelworkqueue.o uiaction.o variablegroupsetmemberselectionchange.o kadwidgetsscrollarea.o kadspinbox.o kadcountchange.o generateoutput.o newgenedatetimewidget.o timerangechange.o newgenegenerateoutput.o generaloptions.o qrc_NewGeneResources.o moc_newgenemainwindow.o moc_newgenecreateoutput.o moc_newgeneselectvariables.o moc_newgenevariablesummary.o moc_newgenetabwidget.o moc_newgenevariablegroup.o moc_newgenevariables.o moc_newgenevariablegroupsscrollarea.o moc_newgenevariablestoolboxwrapper.o moc_newgenevariablestoolbox.o moc_newgenevariablesummaryscrollarea.o moc_newgenevariablesummarygroup.o moc_kadcolumnselectionbox.o moc_timerangebox.o moc_uisettingsmanager.o moc_uimodelmanager.o moc_uidocumentmanager.o moc_uistatusmanager.o moc_globalsettingchangerequestindicator.o moc_globalsettingchangeresponseindicator.o moc_globalsettingchangerequestitem.o moc_globalsettingchangeresponseitem.o moc_projectsettingchangerequestindicator.o moc_projectsettingchangeresponseindicator.o moc_projectsettingchangerequestitem.o moc_projectsettingchangeresponseitem.o moc_modelchangeresponse.o moc_modelchangerequest.o moc_modelchangeindicator.o moc_modelchangeresponseitem.o moc_modelchangerequestitem.o moc_modelchangeitem.o moc_uiprojectmanager.o moc_uiloggingmanager.o moc_newgeneapplication.o moc_uimessager.o moc_uiinputproject.o moc_uioutputproject.o moc_uiinputmodel.o moc_uioutputmodel.o moc_uiinputprojectsettings.o moc_uioutputprojectsettings.o moc_uiallglobalsettings.o moc_uithreadmanager.o moc_uitriggermanager.o moc_uiinputmodelsettings.o moc_uioutputmodelsettings.o moc_workqueuemanager.o moc_uiuidatamanager.o moc_uiuiactionmanager.o moc_uimodelactionmanager.o moc_kadwidgetsscrollarea.o moc_kadspinbox.o moc_newgenedatetimewidget.o moc_newgenegenerateoutput.o
-F/Users/administrator/Qt/5.1.1/clang_64/lib -L/Users/administrator/newgene/NewGeneUI/NewGene/../../NewGeneBackEnd/OSX/NewGene/DerivedData/NewGene/Build/Products/Debug -lNewGene -L/Users/administrator/boost_1_54_0/lib -lboost_filesystem -framework QtWidgets -framework QtGui -framework QtCore -framework OpenGL -framework AGL

解决方案

A giveaway was the std::__1 in the linker's warning message. It was an indication that libc++ internally creates a distinct namespace for standard library classes such as string specifically to force linker errors, because the C++ library that is included by default on OS X is incompatible with use of libc++.

More details, with links, are given in a question I posted while attempting to answer this question: Boost: Why is toolset listed in ~/user-config.jam not available to ./b2?

The answer is to rebuild Boost on OS X, specifying both clang as the compiler, and libc++ as the standard C++ library. (Again, see linked question for details.)

这篇关于铛链接报告&QUOT;找不到符号&QUOT ;,尽管“纳米-m”透露,该名在正在对链接库的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆