Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Ridiculous Linker Error?

Ridiculous Linker Error?
Thread Tools
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
Dec 24, 2002, 11:35 PM
 
Hi,
Here's my problem:
I'm trying to make a set of constants that will be used by my entire program. So, I made a separate class called CPCons that houses all of the static constants. Like so:
Code:
//CPCons.C class CPCons{ public: static double unitLength; static double gapSpace; static int tilesPerColumn; static int tilesPerRow; static int oldXLoc; static int oldYLoc; static int newXLoc; static int newYLoc; //Camera Variables static float cameraXValue; static float cameraYValue; static float cameraZValue; static float totalCameraDistance; static float cameraElevationAngle; static float cameraTwistAngle; static float maxSeeingDistance; };
Then, inside of another file:

Code:
//Main file, whatever... #include "CPCons.C" int main(int argc, char** argv){ /*INITIALIZE THE CONSTANTS!!!!!! */ CPCons::unitLength = 3.0; CPCons::gapSpace = 0.3; CPCons::tilesPerColumn = 6; CPCons::tilesPerRow = 10; CPCons::oldXLoc = 0; CPCons::oldYLoc = 0; CPCons::newXLoc = 0; CPCons::newYLoc = 0; //Camera Variables CPCons::cameraXValue = 0; CPCons::cameraYValue = 0; CPCons::cameraZValue = 50.0; CPCons::totalCameraDistance = 50.0; CPCons::cameraElevationAngle = 40.0; CPCons::cameraTwistAngle = - 90.0; CPCons::maxSeeingDistance = 100.0; }
I get a linker error saying:
warning: prebinding was disabled because of undefined symbols.
Undefined Symbols:

Here's wha the build log says:

/usr/bin/jam -d1 JAMBASE=/Developer/Makefiles/pbx_jamfiles/ProjectBuilderJambase JAMFILE=- build ACTION=build _DEFAULT_GCC_VERSION=3.1 BUILD_STYLE=Development "CPP_HEADERMAP_FILE=/Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.build/Cheesy Pursuit.build/Cheesy Pursuit.hmap" SRCROOT=/Users/gtaubman/Desktop/CheesyPursuit OBJROOT=/Users/gtaubman/Desktop/CheesyPursuit/build SYMROOT=/Users/gtaubman/Desktop/CheesyPursuit/build "DSTROOT=/tmp/Cheesy Pursuit.dst"
...updating 11 target(s)...
Cp /Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.app/Contents/PkgInfo
BuildPhase <CopyResources>Cheesy Pursuit.app
Completed phase <CopyResources> for <CopyResources>Cheesy Pursuit.app
CompileCplusplus /Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.build/Cheesy Pursuit.build/Objects-normal/ppc/CMain.o
BuildPhase <DeriveAndCompileSources>Cheesy Pursuit.app
Completed phase <DeriveAndCompileSources> for <DeriveAndCompileSources>Cheesy Pursuit.app
MasterObjectFile.Combine /Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.build/Cheesy Pursuit.build/Objects-normal/ProjectBuilderMasterObjectFile.o
StandaloneExecutable /Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.app/Contents/MacOS/Cheesy Pursuit
ld: warning prebinding disabled because of undefined symbols
ld: Undefined symbols:
CPCons::unitLength
CPCons::tilesPerRow
CPCons::cameraXValue
CPCons::cameraYValue
CPCons::cameraZValue
CPCons::tilesPerColumn
CPCons::cameraTwistAngle
CPCons::maxSeeingDistance
CPCons::totalCameraDistance
CPCons::cameraElevationAngle
CPCons::newXLoc
CPCons::newYLoc
CPCons::oldXLoc
CPCons::oldYLoc
CPCons::gapSpace

/usr/bin/g++3 -o "/Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.app/Contents/MacOS/Cheesy Pursuit" "-L/Users/gtaubman/Desktop/CheesyPursuit/build" "-F/Users/gtaubman/Desktop/CheesyPursuit/build" -filelist "/Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.build/Cheesy Pursuit.build/Objects-normal/LinkFileList" "-arch" "ppc" "-prebind" "-framework" "OpenGL" "-framework" "GLUT" "-lobjc" "-framework" "OpenGL" "-framework" "GLUT"

...failed StandaloneExecutable.LinkUsingFileList /Users/gtaubman/Desktop/CheesyPursuit/build/Cheesy Pursuit.app/Contents/MacOS/Cheesy Pursuit ...

Any ideas? I'm completely stumped. It all compiles fiine up to there. It seems like .o files aren't getting linked together, or something stupid. I just can't find the problem. Any help would be appreciated. Thanks again.

Gabe
(Last edited by Zimwy; Dec 24, 2002 at 11:51 PM. )
     
Fresh-Faced Recruit
Join Date: Oct 2001
Location: Vancouver, BC Canada.
Status: Offline
Reply With Quote
Dec 25, 2002, 04:58 PM
 
in one of the compiled files you need to define the static variables in the global space and assign it
so:

#include "CPCons.h"

double CPCons::unitLength = 3.0;
// Add all the statics here

void main()
{
[...]
}
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Dec 25, 2002, 08:19 PM
 
You need a separate header and implementation file (a .h and a .C file). Use #ifdef and #endif style statements to ensure that the header file is only read once. Inside of that, after the declaration of the class, you should actually instantiate an object. In the constructor of the object, you will need to set up all of the constant values. Doing it this way, all code files that include the header should have access to the universal constants object. Also, changing the constants will not require recompiling all of these files.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Boulder, CO, USA
Status: Offline
Reply With Quote
Dec 26, 2002, 09:14 PM
 
bertrandl's got your back. the linker is complaining that those members have been declared but not defined.

if you're only using those constants in the main file, go ahead and define them there. if you want to use them elsewhere, bite the bullet and make .h and .c files. you can declare them as often as you like, but you must only define them once. "One ping only, please."

also ... try a namespace. tastes great, less filling!
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
Dec 27, 2002, 05:40 PM
 
Originally posted by aleph_null:

also ... try a namespace. tastes great, less filling!
I did try that. It said it wasn't declared. How do I declare a namespace? Thanks!!

Gabe
     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Dec 27, 2002, 08:44 PM
 
Code:
namespace CPCons { const double unitLength = 3.0; const double gapSpace = 0.3; const int tilesPerColumn = 6; const int tilesPerRow = 10; const int oldXLoc = 0; const int oldYLoc = 0; const int newXLoc = 0; const int newYLoc = 0; //Camera Variables const float cameraXValue = 0; const float cameraYValue = 0; const float cameraZValue = 0; const float totalCameraDistance = 50.0; const float cameraElevationAngle = 40.0; const float cameraTwistAngle = -90.0; const float maxSeeingDistance = 100.0; }
[vash:~] banana% killall killall
Terminated
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:59 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2