我正在编写一个相当大的 C + + 共享对象库,遇到了一个小问题,这个问题让调试变得很麻烦:
如果我在一个头文件中定义一个函数/方法,并且忘记为它创建存根(在开发过程中) ,因为我是作为一个共享对象库而不是一个可执行文件来构建的,那么在编译时就不会出现错误,告诉我我忘记实现那个函数了。我发现问题的唯一方法是在运行时,当最终链接到这个库的应用程序出现“未定义的符号”错误时。
我正在寻找一种简单的方法来检查我是否有所有的符号,我需要在编译时,也许我可以添加到我的 Makefile。
One solution I did come up with is to run the compiled library through nm -C -U
to get a demangled list of all undefined references. The problem is this also comes up with the list of all references that are in other libraries, such as GLibC, which of course will be linked against along with this library when the final application is put together. It would be possible to use the output of nm
to grep
through all my header files and see if any of the names corresponding.. but this seems insane. Surely this is not an uncommon issue and there is a better way of solving it?