调试中出现不满意的符号,但发布中却没有出现不满意的符号
我正在 HPUX 上构建一些东西。代码在 Sun/Linux/AIX 中运行良好。
抱怨
[sshexec] /usr/ccs/bin/ld: Unsatisfied symbols:
[sshexec] globalVar (first referenced in blah.o)
但在 HPUX 上,它再次 代码在发布中有效,但在调试中无效。 它所做的只是使用其他文件
extern globPck globalVar;
globPck 中定义的全局变量,它是包含一些全局内容的类。
我更感兴趣的是,这可能是在发布中起作用但在调试中不起作用的原因。
我查看了 .i 文件(使用 -E 生成的预编译头文件) 它似乎以同样的方式定义。
我猜测发布代码路径中遇到的某些问题可以修复它,但我来这里是为了听听你们是否有一些想法。
I am building something on HPUX. Code works fine in Sun/Linux/AIX.
But on HPUX it complains on
[sshexec] /usr/ccs/bin/ld: Unsatisfied symbols:
[sshexec] globalVar (first referenced in blah.o)
Once again code works in Release but not in Debug.
All it does it uses global variable defined in some other file
extern globPck globalVar;
globPck is class that cointains some global stuff.
I am more interested in ideas what could be the reason for this to work in Release but not in Debug.
I looked over .i files (precompiled header file generated with -E)
And it seems defined in same way.
I am guessing something that is hit in Release code path fixes it but I am here to hear if yall have some ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当链接器抱怨某些内容未定义时,要做的第一件事就是自己查找该内容的定义位置。如果你找不到它,那么也不要指望链接器能找到它。
您所显示的是声明,而不是定义。定义不会有
extern
关键字。项目中的一个 .cpp 文件中应该有一个定义,而不是标头。找到定义后,您就可以开始研究链接器看不到它的原因。也许它仅在存在某些符号时定义,例如
DEBUG
或NDEBUG
。如果没有定义,那么它的所有使用可能会在发布编译期间被删除(可能是因为所有使用都发生在编译器省略的
assert
语句中),因此缺少定义在发布模式下不会被注意到。The first thing to do when the linker complains that something isn't defined is to go find for yourself where that thing is defined. If you can't find it, then don't expect the linker to find it, either.
What you have shown is a declaration, not a definition. A definition will not have the
extern
keyword. There should be a definition in exactly one .cpp file in your project, not a header.Once you've found the definition, then you can start working on why the linker doesn't see it. Maybe it's only defined when certain symbols are present, such as
DEBUG
orNDEBUG
.If there is no definition, then maybe all uses of it get removed during release compilation (perhaps because all uses occur in
assert
statements that the compiler omits), so the missing definition isn't noticed in release mode.如果仅从主执行路径间接访问类,HPUX 编译器喜欢“优化”对全局类的构造函数调用。尝试在主线程中的某处添加一个带有变量值的简单 printf() ,看看问题是否消失。
The HPUX Compiler loves to "Optimize away" Constructor calls to global classes if the classes are only accessed indirectly from the main path of execution. Try adding a simple printf() with the value of the variable in your main thread somewhere an see if the problem dissappears.