g ++未定义的符号使用共享库时出错 [英] g++ Undefined Symbol Error using shared library

查看:162
本文介绍了g ++未定义的符号使用共享库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

符号在文件中。我使用nm& grep但是我仍然得到未定义的符号错误,当我运行编译的应用程序。共享库中的其他符号工作正常。头文件将其声明为extern,并且不在条件预处理器块中。我是新来的c / c ++,所以任何像这样的东西的经验将不胜感激。

The symbol is in the file. I verified it using nm & grep but I still get the undefined symbol error when I run the compiled application. Other symbols in the shared library are working just fine. The header file declares it as extern and it is not in a conditional pre-processor block. I'm new to c/c++ so any experience with something like this would be appreciated.

StackOverflow有大量的相关问题,但每个人都列出源文件和标题,这并不意味着问题的实际上下文。这是一个一般的编程问题:为什么不能g ++链接符号到我的编译应用程序?

There are a ton of related questions on StackOverflow, but everyone is listing source files and headers that don't mean anything to the actual context of the question. This is a general programming question: Why can't g++ link the symbol into my compiled application? Header definition checks ok, the symbol is in the shared library, and other symbols are working properly.

推荐答案

您需要设置您的LD_LIBRARY_PATH环境变量,包括您的开发版本的库的路径。这将确保运行时链接器(ld.so)将在您运行应用程序时找到它。

You need to set your LD_LIBRARY_PATH environment variable to include the path to your development version of the library. This will ensure the run time linker (ld.so) will find it when you run your application.

您的构建设置很好,但它们不会影响运行。如果你真的想要的话,有一些方法可以在构建时烘焙可执行文件的路径。请参阅ld.so的手册页查看如何搜索库。

Your build settings are fine but they don't affect what happens at run time. There are ways to "bake" paths into the executable at build time if you really want to. See the man page for ld.so to see how it searches for libraries.

这篇关于g ++未定义的符号使用共享库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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