Linking Error... I'm Stumped

Started by
11 comments, last by tcabe 22 years, 3 months ago
Hello, I have copied some code from the adventure demo into my home grown app ... basically the high level stuff to get a LS level up and running. However I am receiving a link error on the code that I copied. On the following line, within the void DisplayingLevel (void) function: LS_DrawWorld (GameTicks); If I comment the line out, the application links fine, however if I include it I get the follow error message: Linking... TerrainEngine.lib(RenderWorld.obj) : error LNK2001: unresolved external symbol _userlights exeRelease/Main.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I spent hours last night working on this and was able to find that line above but now I''m stumped. Anyone know what is going on and can help me get past this? Thanks, Tony Cabe
Advertisement
what is there not to understand. it''s saying "_userlights" is not defined. DEFINE IT.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Thanks for your expert help, but it is defined. If its not defined it gives an error like the following:

Compiling...
Main.cpp
C:\PR4\utility\World\srcMain\Main.cpp(88) : error C2065: ''userlights'' : undeclared identifier
C:\PR4\utility\World\srcMain\Main.cpp(94) : error C2228: left of ''.NumLights'' must have class/struct/union type
Error executing cl.exe.


If you notice its a COMPILE error above, I''m asking about a linking error that, according to the compile, is in TerrainEngine.lib(RenderWorld.obj).

Still stumped,

Tony Cabe
notice how the compile error says "undeclared". that is not "undefined".

here''s how it works when you compile a source file, symbol references do not have a "resolved" address, there for they are "unresolved". when you link object files together, these need to become resolved. if a symbol is not defined then it is "unresolved" and the "linker" returns an error. this does not apply to "dynamic symbols" which get linked at run-time. however, you will get a run-time error if they are not resolved at that point.

you can DECLARE a function "void func(void);" to DEFINE the function you need to give it a body.

i.e.
void func(void)
{
}

these two are not the same thing.

if you can specify if "userlights" is a class, variable, member name, struct, etc. i can probably explain how to solve this problem.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Hello,

I''m not sure if I have the terminology correct yet, but here goes....

I copied the declaration for userlights from the adventure demo, it looks like this.

PR_LIGHTLIST userlights; /* Holds a list of lights */


PR_LIGHTLIST is a structure. I have it as a global variable just as in the adventure demo. Is this the information you needed?

I''m cofused as to why the link error is in the TerrainEngine.lib?

Thanks for looking at this.

Tony Cabe

ahhh, global variables...

ok, if "userlights" is not defined specifically in the "RenderWorld.obj" source file.

meaning "PR_LIGHTLIST userlights;"

if it is defined in another source file then you will need to include the line "extern PR_LIGHTLIST userlights;".

so the compiler and linker knows that this variable is defined externally from the "RenderWorld.obj" file.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
The terrain engine (AKA high level engine) uses the userlights structure.

Since you''re using C++ you need to define it using the C naming convention in your .CPP file:

#ifdef __cplusplus
extern "C" {
#endif

// .. define variables referenced by external C sources here
PR_LIGHTLIST userlights;

#ifdef __cplusplus
}
#endif

Author of Power Render (http:/www.powerrender.com)
I thank you both for your kindness and your expert help. I have a better understanding of declaration vs. definition as well as c vs. cpp usage. This problem appears to be solved (or at least it compiles and links), now on to the next.

Thanks again,

Tony Cabe

Chris,

Are there any other variables that need to be defined like this? I am really having a hard time getting the user control section to come into cpp and actually work.

Thanks,

Tony
tcabe...

I''ve been working so hard for the last year trying to get PR incapsulated into some classes that I finally made it.

What are your problems exactly ?....

If it is related to installkbd and other mouse things, I would suggest you to do the following :

1/ In the main cpp file of your project, add the following code if it isn''t yet :

  #ifdef __cplusplusextern "C" {#endif    char kbdon[256];    PR_MouseStructData mouse;#ifdef __cplusplus};      // Do not forget the '';'' if not there it do not work.#endif  


2/ Then, I suggest that you implement your own DirectInput8 code using one of the available tutorials or samples of the DirectX SDK.

3/ Take a very big caution on how PR works in the Main Window Proc function and try to recreate what you ned from it. That''s a really important point. PowerRender uses this function to handle, for example, viewport resizing when you are in windowed mode.

4/ Take a coffee... ;-)

I may be releasing my wrapper classes dll somewhere if it passes two or three tests before :
1/ it definiively works in any situation,
2/ I make a descent tutorial (even if my code is clear and well documented it needs one)
3/ It needs PR libs to compile cause I don''t want to be a tension for Chris and he disserves to wn his life with that engine. It''s a PR wrapper, not a full 3d engine as he has been working on for a long time now.

Amadrias
France

This topic is closed to new replies.

Advertisement