473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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@@3PAY03USurfacePoint@@A) already defined in Project.obj; second definition ignored
1>E:\c++\sdl2\Release\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@@3PAY03USurfacePoint@@A) already defined in CIL library( CIL module); second definition ignored
1>E:\c++\sdl2\Release\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\BuildLog.htm"
1>sdl - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Here is surf class:

Expand|Select|Wrap|Line Numbers
  1. #include "SDL.h"         // SDL: window & input library
  2. #include "SDL_opengl.h"  // platform independent OpenGL include
  3. #include <vector>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7. #include <math.h>
  8. #include <stdio.h>
  9. #include <stdlib.h> 
  10. using namespace std;
  11.  
  12.  
  13.  
  14. struct SurfacePoint {
  15.  
  16.  
  17.     float x;
  18.     float y;
  19.     float z;
  20. };
  21.  
  22. /// 4x4 grid of SurfacePoints that will define the surface
  23. SurfacePoint Points[4][4] = { 
  24.     {
  25.         { 10,0,10 },
  26.         {  5,0,10 },
  27.         { -5,0,10 },
  28.         {-10,0,10 }
  29.     },
  30.     {
  31.         { 10,0,5 },
  32.         {  5,6,5 },
  33.         { -5,6,5 },
  34.         {-10,0,5 }
  35.     },
  36.      {
  37.         { 10,0,-5 },
  38.         {  5,6,-5 },
  39.         { -5,6,-5 },
  40.         {-10,0,-5 }
  41.     },
  42.     {
  43.         { 10,0,-10 },
  44.         {  5,0,-10 },
  45.         { -5,0,-10 },
  46.         {-10,0,-10 }
  47.     }
  48. };
  49.  
  50. class surf{
  51.  
  52.     float detail;
  53.  
  54.  
  55.  
  56. public:
  57.  
  58.     surf(){
  59.         detail=(float)0.01;            //step for u and v values
  60.     }
  61.  
  62.     void draw(){
  63.  
  64.         glBegin(GL_POINTS);
  65.         //get SurfacePoints on u curves
  66.         for (float u=0;u<1;u+=detail){
  67.             for(float v=0;v<1;v+=detail){
  68.  
  69.  
  70.             SurfacePoint p=calculate(u,v);
  71.             glVertex3f(p.x,p.y,p.z);
  72.             }
  73.  
  74.  
  75.         }
  76.  
  77.     glEnd();
  78.  
  79.  
  80.     }
  81.  
  82.     SurfacePoint calculate(float u, float v){
  83.  
  84.     //calculate 4 SurfacePoints on each u curve
  85.     SurfacePoint temp[4];
  86.     temp[0] = calculate_u(u,0);
  87.     temp[1] = calculate_u(u,1);
  88.     temp[2] = calculate_u(u,2);
  89.     temp[3] = calculate_u(u,3);
  90.  
  91.     return calculate_v(v,temp);
  92.     }
  93.  
  94.     SurfacePoint calculate_u(float u, int row){
  95.  
  96.     SurfacePoint p;
  97.  
  98.     //BLENDING FUNCTION
  99.  
  100.     float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f;
  101.     float b1 = (3*u*u*u - 6*u*u +4)/6.0f;
  102.     float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f;
  103.     float b3 =  u*u*u/6.0f;
  104.  
  105.     p.x = b0*Points[row][0].x +
  106.           b1*Points[row][1].x +
  107.           b2*Points[row][2].x +
  108.           b3*Points[row][3].x ;
  109.  
  110.     p.y = b0*Points[row][0].y +
  111.           b1*Points[row][1].y +
  112.           b2*Points[row][2].y +
  113.           b3*Points[row][3].y ;
  114.  
  115.     p.z = b0*Points[row][0].z +
  116.           b1*Points[row][1].z +
  117.           b2*Points[row][2].z +
  118.           b3*Points[row][3].z ;
  119.  
  120.  
  121.     return p;
  122.  
  123.     }
  124.  
  125.     SurfacePoint calculate_v(float u,SurfacePoint* pts){
  126.  
  127.     SurfacePoint p;
  128.  
  129.     float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f;
  130.     float b1 = (3*u*u*u - 6*u*u +4)/6.0f;
  131.     float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f;
  132.     float b3 =  u*u*u/6.0f;
  133.  
  134.     p.x = b0*pts[0].x + 
  135.           b1*pts[1].x + 
  136.           b2*pts[2].x + 
  137.           b3*pts[3].x ;
  138.  
  139.     p.y = b0*pts[0].y + 
  140.           b1*pts[1].y + 
  141.           b2*pts[2].y + 
  142.           b3*pts[3].y ;
  143.  
  144.     p.z = b0*pts[0].z + 
  145.           b1*pts[1].z + 
  146.           b2*pts[2].z + 
  147.           b3*pts[3].z ;
  148.  
  149.  
  150.     return p;
  151.  
  152.     }
  153.  
  154.  
  155.  
  156.  
  157.  
  158. };
here is the main file :

Expand|Select|Wrap|Line Numbers
  1. /* SDL OpenGL skeleton code. *
  2.  * by Fredrik Orderud, 2005  */
  3.  
  4. #include "SDL.h"         // SDL: window & input library
  5. #include "SDL_opengl.h"  // platform independent OpenGL include
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "surface.cpp"
  10.  
  11. bool running = true;
  12. surf t;
  13. /* Keyboard callback */
  14. static void handle_key_down (SDL_keysym* keysym) {
  15.     switch( keysym->sym ) {
  16.     case SDLK_ESCAPE:
  17.     case SDLK_q:
  18.     case SDLK_x:
  19.         running = false;
  20.         break;
  21.     case SDLK_SPACE:
  22.         // do something :)
  23.         break;
  24.          }
  25. }
  26.  
  27. /* General event callback */
  28. static void process_events () {
  29.     SDL_Event event;
  30.  
  31.     // Grab all the events off the queue
  32.     while (SDL_PollEvent(&event)) {
  33.         switch( event.type ) {
  34.         case SDL_KEYDOWN:
  35.             // key presses
  36.             handle_key_down( &event.key.keysym );
  37.             break;
  38.         case SDL_QUIT:
  39.             // quit requests (like Ctrl-c)
  40.             running = false;
  41.             break;
  42.         }
  43.     }
  44. }
  45.  
  46. /* Render scene */
  47. static void draw_scene () {
  48.     // clear image- and depth buffer to get a clean canvas
  49.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  50.  
  51.     // set up geometric transformations
  52.     glMatrixMode(GL_MODELVIEW);
  53.     glLoadIdentity();
  54.  
  55.     glTranslatef(0.0f,-6.0f,-10.0f);
  56.     // Now looking in negative Z-direction from origo
  57.     // +X is right and +Y is up
  58. t.draw();
  59.     /* TODO:
  60.     Insert geometric camera-transformation code here
  61.     to convert from "camera" to "world" frame */
  62.  
  63.     //Render object(s)
  64.     // TODO: REPLACE CODE HERE
  65.  
  66.  
  67.     //  Swap on-screen/off-screen buffers (double buffering)
  68.     SDL_GL_SwapBuffers( );
  69. }
  70.  
  71. /* Initialize OpenGL */
  72. static void setup_opengl( int width, int height ) {
  73.     // Gouraud shading model (smooth)
  74.     glShadeModel(GL_SMOOTH);
  75.  
  76.     // enable backface culling
  77.     glCullFace(GL_BACK);
  78.     glFrontFace(GL_CCW);
  79.     glEnable(GL_CULL_FACE);
  80.  
  81.     // Set black clear color
  82.     glClearColor(0, 0, 0, 0);
  83.     // Enable Z-buffer (corrects drawing order)
  84.     glEnable(GL_DEPTH_TEST);
  85.  
  86.     // Let viewport cover entire window
  87.     glViewport(0, 0, width, height);
  88.  
  89.     // Change to the projection matrix and set our viewing volume.
  90.     glMatrixMode(GL_PROJECTION);
  91.     glLoadIdentity();
  92.     float ratio = (float) width / (float) height;
  93.     gluPerspective(60.0, ratio, 1.0, 1024.0);
  94. }
  95.  
  96. /* Program entry point */
  97. int main (int argc, char* argv[]) {
  98.     // window dimensions
  99.     int width  = 640;
  100.     int height = 480;
  101.  
  102.     // initialize SDL's video subsystem
  103.     if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
  104.         fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) );
  105.         return -1;
  106.     }
  107.  
  108.     // retrieve video information
  109.     const SDL_VideoInfo *info = SDL_GetVideoInfo( );
  110.     if (!info) {
  111.         fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) );
  112.         return -1;
  113.     }
  114.  
  115.     SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   8 ); // min 8bit red
  116.     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 ); // min 8bit green
  117.     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  8 ); // min 8bit blue
  118.     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); // 16bit depth buffer
  119.     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // require double buffering
  120.  
  121.     // Set video mode
  122.     SDL_Surface * surface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL);
  123.     if (!surface) {
  124.         fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
  125.         return -1;
  126.     }
  127.  
  128.     // OpenGL initialization
  129.     setup_opengl(width, height);
  130.  
  131.     // main event loop
  132.     while (running) {
  133.         // Process incoming events
  134.         process_events();
  135.         // Draw the screen
  136.         draw_scene();
  137.  
  138.         SDL_Delay(10/5); // 5fps
  139.     }
  140.  
  141.     SDL_Quit(); // unload SDL
  142.     return 0;
  143. }
  144.  
  145.  
  146.  
Sep 26 '06 #1
2 8519
Banfa
9,065 Expert Mod 8TB
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

Expand|Select|Wrap|Line Numbers
  1. /// 4x4 grid of SurfacePoints that will define the surface
  2. SurfacePoint Points[4][4] = { 
  3.     {
  4.         { 10,0,10 },
  5.         {  5,0,10 },
  6.         { -5,0,10 },
  7.         {-10,0,10 }
  8.     },
  9.     {
  10.         { 10,0,5 },
  11.         {  5,6,5 },
  12.         { -5,6,5 },
  13.         {-10,0,5 }
  14.     },
  15.      {
  16.         { 10,0,-5 },
  17.         {  5,6,-5 },
  18.         { -5,6,-5 },
  19.         {-10,0,-5 }
  20.     },
  21.     {
  22.         { 10,0,-10 },
  23.         {  5,0,-10 },
  24.         { -5,0,-10 },
  25.         {-10,0,-10 }
  26.     }
  27. };
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

Expand|Select|Wrap|Line Numbers
  1. /// 4x4 grid of SurfacePoints that will define the surface
  2. extern SurfacePoint Points[4][4];
  3.  
in the header file. This is a declaration and tells the code that this variable exists and is defined else where.
Sep 27 '06 #2
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
Sep 27 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Jim Hubbard | last post by:
I am reposting a portion of a thread that I am involved in under a new topic because it seems that there are still people that believe the whole "DLL Hell" myth. I hope I can shed some light on...
2
by: Nad | last post by:
Hello, dll hell has been eliminated in .NET using assembly versioning. I am new in .NET and would like to know if there is any dll-hell-equivalent in .NET Windows or Web development...
1
by: GreatB | last post by:
Bill Gates died in a car accident. He found himself in Purgatory being sized up by God . .. "Well, Bill, I'm really confused on this call. I'm not sure whether to send you to Heaven or Hell....
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
3
by: fyleow | last post by:
I just spent hours trying to figure out why even after I set my SQL table attributes to UTF-8 only garbage kept adding into the database. Apparently you need to execute "SET NAMES 'utf8'" before...
2
by: Scott M. | last post by:
I need a little help please... I'm simply trying to set up a very basic event for a class and then create an event handler for that class in a Console application. I think I'm very close, but...
1
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include...
9
by: dewi | last post by:
Dear All, I have several problem about VC++. I succeed to convert Simulink MATLAB to C code using Real-Time Workshop. I am trying to compile a C code using Visual C++ and found the error. Can...
3
by: khumayun | last post by:
Hi, I basically making a static library of my own. I have taken my code which works and now put it into a static library for another program to use. In my library I am using another static library...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.