문제

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.

도움이 되었습니까?

해결책

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 or NDEBUG.

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top