Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:17:21+00:00 2026-06-13T21:17:21+00:00

I’m getting stranger error when I compile my code. I guess the header files

  • 0

I’m getting stranger error when I compile my code. I guess the header files aren’t being properly linked because every single one of those variables that are erroring have been specified in ‘variables.h’ which I properly #include. Strangely enough, if I comment ou the areas in which the variables are used in main.cpp, a whole other slew of errors pop up of the same variables in another file readfile.cpp. Below is the error output, as well as my code for main.cpp and variables.h. Any ideas?

g++ -c main.cpp 
g++ -c readfile.cpp 
g++ -c Objects.cpp 
g++ -o raytracer main.o readfile.o Objects.o
Undefined symbols for architecture x86_64:
  "_depth", referenced from:
      init()    in main.o
      readFile(char const*)in readfile.o
  "_diffuse", referenced from:
      readFile(char const*)in readfile.o
  "_emission", referenced from:
      readFile(char const*)in readfile.o
  "_filename", referenced from:
      init()    in main.o
  "_fov", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_height", referenced from:
      init()    in main.o
      readFile(char const*)in readfile.o
  "_lookatx", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_lookaty", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_lookatz", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_lookfromx", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_lookfromy", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_lookfromz", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_maxvertnorms", referenced from:
      init()    in main.o
      readFile(char const*)in readfile.o
  "_maxverts", referenced from:
      init()    in main.o
      readFile(char const*)in readfile.o
  "_shininess", referenced from:
      readFile(char const*)in readfile.o
  "_specular", referenced from:
      readFile(char const*)in readfile.o
  "_spherecount", referenced from:
      init()    in main.o
  "_spheres", referenced from:
      readFile(char const*)in readfile.o
  "_triangles", referenced from:
      readFile(char const*)in readfile.o
  "_tricount", referenced from:
      init()    in main.o
  "_trinormals", referenced from:
      readFile(char const*)in readfile.o
  "_trinormcount", referenced from:
      init()    in main.o
  "_upx", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_upy", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_upz", referenced from:
      init()    in main.o
      initCamera(float*)in readfile.o
  "_vertexcount", referenced from:
      init()    in main.o
  "_vertexnormcount", referenced from:
      init()    in main.o
  "_vertices", referenced from:
      readFile(char const*)in readfile.o
  "_vertnormals", referenced from:
      readFile(char const*)in readfile.o
  "_width", referenced from:
      init()    in main.o
      readFile(char const*)in readfile.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Below is variables.h..

#include "vertexnormal.h"
#include "sphere.h"
#include "tri.h"
#include "trinormal.h"
#include "vec.h"

#include <string>
#include <vector>

using namespace std;

// width and height specify image size
extern float width;
extern float height;

// maximum depth for a ray (level of recursion)
extern int depth;

// the output file to which the image should be written
extern string filename;

// camera specifiations (should i put in a struct?)
extern float lookfromx;
extern float lookfromy;
extern float lookfromz;
extern float lookatx;
extern float lookaty;
extern float lookatz;
extern float upx;
extern float upy;
extern float upz;
extern float fov;

//***************************//
//  Geometry Specifications  //
//***************************//

// specifies the number of vertrices for tri specifications
extern int maxverts;

// specifies the number of vertices with normals for tri specifications
extern int maxvertnorms;

// pile of inputted vertices
// might need to #include glm file                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
extern vector<vec> vertices;

// pile of inputted vertices with specified normals
extern vector<vertexNormal> vertnormals;

// pile of inputted spheres
extern vector<sphere> spheres;

// pile of inputted triangles
extern vector<tri> triangles;

// pile of inputted triangles using vertices with specified normals 
extern vector<triNormal> trinormals;

extern int vertexcount;
extern int vertexnormcount;
extern int spherecount;
extern int tricount;
extern int trinormcount;

//**************************//
//  Materials Specifiations //
//**************************//

extern float diffuse[3];
extern float specular[3];
extern float shininess;
extern float emission[3];

And here is my main.cpp,

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

#include "Objects.h"

using namespace std;

#include "readfile.h"
#include "variables.h"


void init() {
    cout << "Reading in scene file... \n";
    cout << "Image size has been set to a " << width << " x " << height << " output. /n";
    cout << "The maximum recursion depth has been set to " << depth << ". \n";
    cout << "The image will be output to " << filename << ".png. \n";

    cout << "The camera has been instantiated with the following properties: \n";
    cout << "\t POSITION: (" << lookfromx << ", " << lookfromy << ", " << lookfromz << ") \n";
    cout << "\t DIRECTION: (" << lookatx << ", " << lookaty << ", " << lookatz << ") \n";
    cout << "\t UP: (" << upx << ", " << upy << ", " << upz << ") \n";
    cout << "\t FIELD OF VIEW: " << fov << " \n";

    cout << "An amount of " << vertexcount << " vertices has been specified with a maximum of " << maxverts << " allowed. \n";
    cout << "An amount of " << vertexnormcount << " vertices with normals has been specified with a maximum of " << maxvertnorms << " allowed. \n"; 

    cout << "An amount of " << spherecount << " spheres have been specified. \n";
    cout << "An amount of " << tricount << " triangles have been specified. \n";
    cout << "An amount of " << trinormcount << " triangles with calculated vertex normals have been specified. \n";
}


int main (int argc, char * argv[]) {
    readFile(argv[1]);
    init();
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:17:23+00:00Added an answer on June 13, 2026 at 9:17 pm

    Try this:

    1. Open up your variables.h header file.
    2. Copy ALL of the extern variable declarations.
    3. Open up your main.cpp file.
    4. Paste all your declarations copied from (2).
    5. In the same main.cpp remove the keyword extern from each declaration.
    6. Save all your files.
    7. Lookup how extern works. Something tells me you missed that in your studies.

    Ok, this has been covered in SO what, a few thousand times, but for the OP:

    Declaring the Existence of a Variable

    // DECLARE myvar, an int variable. no storage has been set aside
    //  this is simply telling the compiler this thing exists.. somewhere.
    extern int myvar;
    

    Defining The Existence of a Variable

    // DEFINE myvar, an int variable. storage *is* set aside here.
    //  only ONE of these, by this name, can be in your global 
    //  namespace in your program.
    int myvar = 0;
    

    Traditionally, extern declarations are in headers, but definitions are always in c/cpp files. There must be a matching definition for any extern-declared variable that is used in your program.

    How this fits with your situation
    All of your variables were declared in variables.h, but the were never defined anyway. By telling you to copy/paste all those declarations into a source file (any will do; I chose main.cpp because it was already in your project), and then removing the extern keyword in that source file (not the header), you were essentially defining where they all officially existed. Now all those references to extern‘ed variables in your other source files finally have something to hook up to at link time.

    Sidebar
    In the c/cpp file where your variables are being defined, make sure you initialize them to proper values. This is the one and only place you can do it. you can NOT do it on any extern declaration. It can only be done on a definition.

    Header File

    extern int myvar; // note: no initial value.
    

    Source File

    int myvar = 0; // note: initialized to zero (0)
    

    I hope that made at least a little sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.