LNK4006 hell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stromhau
    New Member
    • Sep 2006
    • 12

    LNK4006 hell

    Hello , i have tried everything but this error wont go away.
    Have tried renaming the struct and the array Points but nothing works.
    Tried rebuilding the class but it wont have an array at all! Please help me :)

    The link error from visual studio 2005 is :

    1>------ Build started: Project: sdl, Configuration: Release Win32 ------
    1>Compiling...
    1>Project.cpp
    1>Linking...
    1>surface.obj : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in Project.obj; second definition ignored
    1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
    1>Generating code
    1>Finished generating code
    1> CIL library( CIL module) : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in CIL library( CIL module); second definition ignored
    1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
    1>Embedding manifest...
    1>Build log was saved at "file://e:\c++\sdl2\sdl \Release\BuildL og.htm"
    1>sdl - 0 error(s), 4 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    Here is surf class:

    Code:
    #include "SDL.h"         // SDL: window & input library
    #include "SDL_opengl.h"  // platform independent OpenGL include
    #include <vector>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h> 
    using namespace std;
    
    
    
    struct SurfacePoint {
    	
    
    	float x;
    	float y;
    	float z;
    };
    
    /// 4x4 grid of SurfacePoints that will define the surface
    SurfacePoint Points[4][4] = { 
    	{
    		{ 10,0,10 },
    		{  5,0,10 },
    		{ -5,0,10 },
    		{-10,0,10 }
    	},
    	{
    		{ 10,0,5 },
    		{  5,6,5 },
    		{ -5,6,5 },
    		{-10,0,5 }
    	},
    	 {
    		{ 10,0,-5 },
    		{  5,6,-5 },
    		{ -5,6,-5 },
    		{-10,0,-5 }
    	},
    	{
    		{ 10,0,-10 },
    		{  5,0,-10 },
    		{ -5,0,-10 },
    		{-10,0,-10 }
    	}
    };
    
    class surf{
    
    	float detail;
    
    
    
    public:
    	
    	surf(){
    		detail=(float)0.01;			//step for u and v values
    	}
    
    	void draw(){
    		
    		glBegin(GL_POINTS);
    		//get SurfacePoints on u curves
    		for (float u=0;u<1;u+=detail){
    			for(float v=0;v<1;v+=detail){
    				
    
    			SurfacePoint p=calculate(u,v);
    			glVertex3f(p.x,p.y,p.z);
    			}
    
    
    		}
    
    	glEnd();
    
    
    	}
    
    	SurfacePoint calculate(float u, float v){
    
    	//calculate 4 SurfacePoints on each u curve
    	SurfacePoint temp[4];
    	temp[0] = calculate_u(u,0);
    	temp[1] = calculate_u(u,1);
    	temp[2] = calculate_u(u,2);
    	temp[3] = calculate_u(u,3);
    
    	return calculate_v(v,temp);
    	}
    	
    	SurfacePoint calculate_u(float u, int row){
    
    	SurfacePoint p;
    
    	//BLENDING FUNCTION
    
    	float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f;
    	float b1 = (3*u*u*u - 6*u*u +4)/6.0f;
    	float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f;
    	float b3 =  u*u*u/6.0f;
    
    	p.x = b0*Points[row][0].x +
    		  b1*Points[row][1].x +
    		  b2*Points[row][2].x +
    		  b3*Points[row][3].x ;
    
    	p.y = b0*Points[row][0].y +
    		  b1*Points[row][1].y +
    		  b2*Points[row][2].y +
    		  b3*Points[row][3].y ;
    
    	p.z = b0*Points[row][0].z +
    		  b1*Points[row][1].z +
    		  b2*Points[row][2].z +
    		  b3*Points[row][3].z ;
    
    
    	return p;
    
    	}
    	
    	SurfacePoint calculate_v(float u,SurfacePoint* pts){
    
    	SurfacePoint p;
    	
    	float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f;
    	float b1 = (3*u*u*u - 6*u*u +4)/6.0f;
    	float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f;
    	float b3 =  u*u*u/6.0f;
    
    	p.x = b0*pts[0].x + 
    		  b1*pts[1].x + 
    		  b2*pts[2].x + 
    		  b3*pts[3].x ;
    
    	p.y = b0*pts[0].y + 
    		  b1*pts[1].y + 
    		  b2*pts[2].y + 
    		  b3*pts[3].y ;
    
    	p.z = b0*pts[0].z + 
    		  b1*pts[1].z + 
    		  b2*pts[2].z + 
    		  b3*pts[3].z ;
    
    
    	return p;
    
    	}
    
    
    
    
    
    };
    here is the main file :

    Code:
    /* SDL OpenGL skeleton code. *
     * by Fredrik Orderud, 2005  */
    
    #include "SDL.h"         // SDL: window & input library
    #include "SDL_opengl.h"  // platform independent OpenGL include
    
    #include <stdio.h>
    #include <stdlib.h>
    #include "surface.cpp"
      
    bool running = true;
    surf t;
    /* Keyboard callback */
    static void handle_key_down (SDL_keysym* keysym) {
        switch( keysym->sym ) {
        case SDLK_ESCAPE:
        case SDLK_q:
        case SDLK_x:
            running = false;
            break;
        case SDLK_SPACE:
            // do something :)
            break;
             }
    }
    
    /* General event callback */
    static void process_events () {
        SDL_Event event;
    
        // Grab all the events off the queue
        while (SDL_PollEvent(&event)) {
            switch( event.type ) {
            case SDL_KEYDOWN:
                // key presses
                handle_key_down( &event.key.keysym );
                break;
            case SDL_QUIT:
                // quit requests (like Ctrl-c)
                running = false;
                break;
            }
        }
    }
    
    /* Render scene */
    static void draw_scene () {
        // clear image- and depth buffer to get a clean canvas
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
        // set up geometric transformations
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
       
    	glTranslatef(0.0f,-6.0f,-10.0f);
    	// Now looking in negative Z-direction from origo
        // +X is right and +Y is up
    t.draw();
        /* TODO:
        Insert geometric camera-transformation code here
        to convert from "camera" to "world" frame */
    
        //Render object(s)
        // TODO: REPLACE CODE HERE
       
    
        //  Swap on-screen/off-screen buffers (double buffering)
        SDL_GL_SwapBuffers( );
    }
    
    /* Initialize OpenGL */
    static void setup_opengl( int width, int height ) {
        // Gouraud shading model (smooth)
        glShadeModel(GL_SMOOTH);
    
        // enable backface culling
        glCullFace(GL_BACK);
        glFrontFace(GL_CCW);
        glEnable(GL_CULL_FACE);
    
        // Set black clear color
        glClearColor(0, 0, 0, 0);
        // Enable Z-buffer (corrects drawing order)
        glEnable(GL_DEPTH_TEST);
    
        // Let viewport cover entire window
        glViewport(0, 0, width, height);
    
        // Change to the projection matrix and set our viewing volume.
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        float ratio = (float) width / (float) height;
        gluPerspective(60.0, ratio, 1.0, 1024.0);
    }
    
    /* Program entry point */
    int main (int argc, char* argv[]) {
        // window dimensions
        int width  = 640;
        int height = 480;
    
        // initialize SDL's video subsystem
        if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
            fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) );
            return -1;
        }
    
        // retrieve video information
        const SDL_VideoInfo *info = SDL_GetVideoInfo( );
        if (!info) {
            fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) );
            return -1;
        }
    
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   8 ); // min 8bit red
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 ); // min 8bit green
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  8 ); // min 8bit blue
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); // 16bit depth buffer
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // require double buffering
    
        // Set video mode
        SDL_Surface * surface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL);
        if (!surface) {
            fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
            return -1;
        }
    
        // OpenGL initialization
        setup_opengl(width, height);
    
        // main event loop
        while (running) {
            // Process incoming events
            process_events();
            // Draw the screen
            draw_scene();
    
            SDL_Delay(10/5); // 5fps
        }
    
        SDL_Quit(); // unload SDL
        return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You should not include surface.cpp, or if it is meant to be a header then surface.cpp should be surface.h

    I assume that the first file posted is this surface.cpp, and I am guessing you include it in more than 1 file.

    In this case you error is cause by this code

    Code:
    /// 4x4 grid of SurfacePoints that will define the surface
    SurfacePoint Points[4][4] = { 
    	{
    		{ 10,0,10 },
    		{  5,0,10 },
    		{ -5,0,10 },
    		{-10,0,10 }
    	},
    	{
    		{ 10,0,5 },
    		{  5,6,5 },
    		{ -5,6,5 },
    		{-10,0,5 }
    	},
    	 {
    		{ 10,0,-5 },
    		{  5,6,-5 },
    		{ -5,6,-5 },
    		{-10,0,-5 }
    	},
    	{
    		{ 10,0,-10 },
    		{  5,0,-10 },
    		{ -5,0,-10 },
    		{-10,0,-10 }
    	}
    };
    This defines the array Points, however if you include it in more than 1 place then Points will be declared in every place you included it and thus multiply defined.

    This code should rised in a cpp file somewhere (see my comment about about not giving header files cpp extentions) and you should put this

    Code:
    /// 4x4 grid of SurfacePoints that will define the surface
    extern SurfacePoint Points[4][4];
    in the header file. This is a declaration and tells the code that this variable exists and is defined else where.

    Comment

    • stromhau
      New Member
      • Sep 2006
      • 12

      #3
      Thank you for answering.

      Yes, the surface.cpp is the first file, and the other file include it. I know this isnt the way to go. Next project i start i will use headerfiles :)
      Strange thing is that surface.cpp is only included in the one file.
      I had to strip things down when i got this error and i ended up with just these two files as posted and still this damn error. When i force it to link its run ok, but i am afraid that this just get worse. Maybe at one stage it wont run. Problem is that i dont know why this error keep bothering me.

      Tommy
      Norway
      Last edited by stromhau; Sep 27 '06, 02:46 PM. Reason: spelling error

      Comment

      Working...