Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Thu Oct 02, 2014 12:19 am

All times are UTC




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Tue Aug 18, 2009 3:44 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3807
Location: South Africa
Removing the .lib reference and adding the glew.c I now get

Quote:
obj\Debug\glew.o:glew.c|9101|first defined here|
obj\Debug\main.o||In function `_Z10initShaderv':|
main.cpp|57|undefined reference to `__imp____glewCreateShader'|
main.cpp|58|undefined reference to `__imp____glewShaderSource'|
main.cpp|59|undefined reference to `__imp____glewCompileShader'|
main.cpp|61|undefined reference to `__imp____glewCreateShader'|
main.cpp|62|undefined reference to `__imp____glewShaderSource'|
main.cpp|63|undefined reference to `__imp____glewCompileShader'|
main.cpp|65|undefined reference to `__imp____glewCreateProgram'|
main.cpp|66|undefined reference to `__imp____glewAttachShader'|
main.cpp|67|undefined reference to `__imp____glewAttachShader'|
main.cpp|68|undefined reference to `__imp____glewLinkProgram'|
main.cpp|70|undefined reference to `__imp____glewUseProgram'|
obj\Debug\glew.o||In function `glewContextInit':|
glew.c|6234|undefined reference to `__imp__glewExperimental'|
glew.c|6237|undefined reference to `__imp__glewExperimental'|
glew.c|6240|undefined reference to `__imp__glewExperimental'|
glew.c|6243|undefined reference to `__imp__glewExperimental'|
glew.c|6246|undefined reference to `__imp__glewExperimental'|
obj\Debug\glew.o:glew.c|6249|more undefined references to `__imp__glewExperimental' follow|
||=== Build finished: 18 errors, 0 warnings ===|



If I remove the -lglew32 as well (so I just have the .h and .c as the only remaining glew stuff) then I get
Quote:
obj\Debug\main.o||In function `_Z10initShaderv':|
main.cpp|57|undefined reference to `__imp____glewCreateShader'|
main.cpp|58|undefined reference to `__imp____glewShaderSource'|
main.cpp|59|undefined reference to `__imp____glewCompileShader'|
main.cpp|61|undefined reference to `__imp____glewCreateShader'|
main.cpp|62|undefined reference to `__imp____glewShaderSource'|
main.cpp|63|undefined reference to `__imp____glewCompileShader'|
main.cpp|65|undefined reference to `__imp____glewCreateProgram'|
main.cpp|66|undefined reference to `__imp____glewAttachShader'|
main.cpp|67|undefined reference to `__imp____glewAttachShader'|
main.cpp|68|undefined reference to `__imp____glewLinkProgram'|
main.cpp|70|undefined reference to `__imp____glewUseProgram'|
obj\Debug\main.o||In function `main':|
main.cpp|75|undefined reference to `__imp__glewInit'|
obj\Debug\glew.o||In function `glewContextInit':|
glew.c|6234|undefined reference to `__imp__glewExperimental'|
glew.c|6237|undefined reference to `__imp__glewExperimental'|
glew.c|6240|undefined reference to `__imp__glewExperimental'|
glew.c|6243|undefined reference to `__imp__glewExperimental'|
glew.c|6246|undefined reference to `__imp__glewExperimental'|
obj\Debug\glew.o:glew.c|6249|more undefined references to `__imp__glewExperimental' follow|
||=== Build finished: 18 errors, 0 warnings ===|



I'm giving up on this endeavour. For starters, I need to set up dual boot at some stage with Ubuntu so that I can get stuff like this to work. I only have knoppix and that doesn't seem to have the right OGL stuff installed. Secondly, I need to learn a shitload more about the linker and compiling in c++. My ability is completely limited to following tutorials to get things set up, so that knowledge clearly needs to get extended.

Thanks for all the help and patience. Unfortunately all I can do on this end is fly-by-wire on instructions, and there's any number of problems that will arise.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 19, 2009 4:05 am 
Level 22 Norse Warrior-Librarian
User avatar

Joined: Mon Sep 04, 2006 5:25 pm
Posts: 579
Location: Tucson, AZ
ya, you need cygwin, because it's relying on the conf utility to actually generate a makefile for you. Cygwin isn't too hard to install, and it's pretty nice to have, so it might be worth a shot :)

After installing it, just add the cygwin/bin/ folder to your %PATH% and you should be able to compile from the command line.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 19, 2009 7:49 am 
Harmlessness does no harm
User avatar

Joined: Tue Sep 14, 2004 8:37 pm
Posts: 3952
Location: Ferriday, LA, US
Yeah, compiling this stuff on an Ubuntu system won't work for Windows. You need cygwin or MinSYS.

Alternatively, look into GLee. It worked much better for me where I couldn't get GLEW to work.

_________________
Wear your sorrows with a smile!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 19, 2009 1:58 pm 
Game Programming Guru

Joined: Sun Aug 15, 2004 6:20 pm
Posts: 1091
IGTHORN wrote:
I'm giving up on this endeavour.

Don't do it. That's what the computer wants you to do!

IGTHORN wrote:
Removing the .lib reference and adding the glew.c I now get

Code:
obj\Debug\glew.o:glew.c|9101|first defined here|
obj\Debug\main.o||In function `_Z10initShaderv':|
main.cpp|57|undefined reference to `__imp____glewCreateShader'|
main.cpp|58|undefined reference to `__imp____glewShaderSource'|
main.cpp|59|undefined reference to `__imp____glewCompileShader'|
main.cpp|61|undefined reference to `__imp____glewCreateShader'|
main.cpp|62|undefined reference to `__imp____glewShaderSource'|
main.cpp|63|undefined reference to `__imp____glewCompileShader'|
main.cpp|65|undefined reference to `__imp____glewCreateProgram'|
main.cpp|66|undefined reference to `__imp____glewAttachShader'|
main.cpp|67|undefined reference to `__imp____glewAttachShader'|
main.cpp|68|undefined reference to `__imp____glewLinkProgram'|
main.cpp|70|undefined reference to `__imp____glewUseProgram'|
obj\Debug\glew.o||In function `glewContextInit':|
glew.c|6234|undefined reference to `__imp__glewExperimental'|
glew.c|6237|undefined reference to `__imp__glewExperimental'|
glew.c|6240|undefined reference to `__imp__glewExperimental'|
glew.c|6243|undefined reference to `__imp__glewExperimental'|
glew.c|6246|undefined reference to `__imp__glewExperimental'|
obj\Debug\glew.o:glew.c|6249|more undefined references to `__imp__glewExperimental' follow|
||=== Build finished: 18 errors, 0 warnings ===|


This does not make much sense to me. My best guess is that you're not compiling glew.c in with your project. Can you provide the total source (keep it minimal, like just main and initShader) and provide the command or steps you're using to compile/link this program? It should look something like
Code:
g++ main.c glew.c -o test -Ipath/glew/include -lopengl32 -lsomeWindowsLibThatCreatesContext


IGTHORN wrote:
Secondly, I need to learn a shitload more about the linker and compiling in c++.

When I see people start out in C++, the learning curve is so steep that I'll find them using things without really understanding what they even do. I did this too (and I continue to do this), since it's easy to get things to work if you just follow how other people do it. It's as if these things are a ritual one must perform to make things magically work. Well, this sucks when things don't go your way and there's no guide to follow.
I think that at some point you need to decide whether you want to do this kind of stuff for a career. If yes, it's worth your time to read manuals, purchase books (even outside of school), understand how the OS works, learn assembly, design and implement your own language/compiler, reimplement lots of things so that you can gain a powerful understanding of all the inner workings.
If you're not interested in all the computing details and just want to do the game dev, I would highly recommend you choose a different set of tools. C++ does not become your best friend until you've spent some quality time together.
What really worries me is that you're trying to jump into the world of shaders and programming the GPU, but your stumped on linking libraries together. It's like you enjoy pain :D

Here are some tips:
During the compile step you can get errors that go like "something is not declared". The compiler is telling you that you're trying to make it use things that you've never provided any information about. This commonly means you're missing a forward declaration (and by extension, you may be missing a header). In your case, your outdated gl.h header was missing the shader functions.

During the link step you may get errors about "unresolved symbols", where the symbol looks weird, but parts of it you may recognize from your code. The compiler must mangle the names according to a calling convention when placing the code into an object file. The linker will look over these object files during the link step and ensure that there is a definition for each symbol used. If one is missing, it spits out the error message that you see. Your initShader function is compiled using the default C++ calling convention. Since C++ supports function overloading, and therefore multiple "initShader" symbols may exist, it must uniquely name it according to its function signature (and it may use other things) to arrive at the symbol "_Z10initShaderv". The GLEW functions you're using are mangled using the C call convention, where overloading does not exist, so they look more like they do in the C source: "__imp____glewCreateShader". I don't know where the "__imp__" prefix comes from, since when I compile glew.c it provides just "__glewCreateShader" (gcc (GCC) 4.4.0 20090526 (prerelease), Linux). I'm hoping someone else can chime in on this one. Compile just the glew.c into a glew.o object file and search it for the symbol "__imp____glewCreateShader". The case may be that you find a glewCreateShader symbol, but it doesn't look exactly the same. This would mean there's an inconsistency with how the compiler is to mangle the names somewhere.
(sorry, didn't mean for these to be so lengthy)

wyrmmage wrote:
ya, you need cygwin, because it's relying on the conf utility to actually generate a makefile for you. Cygwin isn't too hard to install, and it's pretty nice to have, so it might be worth a shot

I think this system is totally s***. It's not unix, it's windows. They should provide a windows way to compile (aside from visual studio), not require some unix environment.

theraje wrote:
Alternatively, look into GLee. It worked much better for me where I couldn't get GLEW to work.

I think that you should take a look at GLEE only after you successfully get GLEW working :)

_________________
Heard in #gpwiki: <wzl> is there some serious grammar fail in your line or am i just too intelligent for your logic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 19, 2009 2:26 pm 
Game Programming Guru

Joined: Sun Aug 15, 2004 6:20 pm
Posts: 1091
I really don't want you to give up. At least get it to compile, link, and execute. If you get runtime errors, then you may give up :P

I downloaded the GLEW source to ./glew. I notice the interfaces are conventiently in ./glew/include, and source in ./glew/src.

ls ./glew/src
Code:
glew.c  glewinfo.c  visualinfo.c


glewinfo.c and visualinfo.c both define main, so I make a reasonable assumption that they are not part of the library. I compile glew.c:

Code:
gcc ./glew/src/glew.c -c -o glew.o -I./glew/include


So far so good. I now have glew.o (about as good as static library for me). Let's compile main.cpp:
main.cpp wrote:
Code:
#include <cstdio>
#include <cstdlib>

#include <GL/glew.h>

using namespace std;

char *file2string(const char *path)
{
   FILE *fd;
   long len,
       r;
   char *str;

   if (!(fd = fopen(path, "r")))
   {
      fprintf(stderr, "Can't open file '%s' for reading\n", path);
      return NULL;
   }

   fseek(fd, 0, SEEK_END);
   len = ftell(fd);

   printf("File '%s' is %ld long\n", path, len);

   fseek(fd, 0, SEEK_SET);

   if (!(str = (char*)malloc(len * sizeof(char))))
   {
      fprintf(stderr, "Can't malloc space for '%s'\n", path);
      return NULL;
   }

   r = fread(str, sizeof(char), len, fd);

   str[r - 1] = '\0'; /* Shader sources have to term with null */

   fclose(fd);

   return str;
}

void initShader(){
    /* The vertex shader */
   const GLchar *vsSource = (GLchar*)file2string("vshader.txt");
   const GLchar *fsSource = (GLchar*)file2string("fshader.txt");

   /* Compile and load the program */

   GLuint vs, /* Vertex Shader */
         fs, /* Fragment Shader */
         sp; /* Shader Program */


   vs = glCreateShader(GL_VERTEX_SHADER);
   glShaderSource(vs, 1, &vsSource, NULL);
   glCompileShader(vs);

   fs = glCreateShader(GL_FRAGMENT_SHADER);
   glShaderSource(fs, 1, &fsSource, NULL);
   glCompileShader(fs);

   sp = glCreateProgram();
   glAttachShader(sp, vs);
   glAttachShader(sp, fs);
   glLinkProgram(sp);

   glUseProgram(sp);
}

int main()
{
   initShader();
   
   return 0;
}



Code:
g++ main.cpp -c -o main.o -I./glew/include


Now I have main.o and glew.o. Let's link them and make our main program:

Code:
g++ main.o glew.o -o main


Errors:
Code:
glew.o: In function `_glewInit_GL_VERSION_1_2':
glew.c:(.text+0x424): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x459): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x48e): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x4c3): undefined reference to `glXGetProcAddressARB'
glew.o: In function `_glewInit_GL_VERSION_1_3':
glew.c:(.text+0x50a): undefined reference to `glXGetProcAddressARB'
glew.o:glew.c:(.text+0x53f): more undefined references to `glXGetProcAddressARB' follow
glew.o: In function `glewGetExtension':
glew.c:(.text+0x13e96): undefined reference to `glGetString'
glew.o: In function `glewContextInit':
glew.c:(.text+0x13f2c): undefined reference to `glGetString'
glew.o: In function `_glewInit_GLX_VERSION_1_2':
glew.c:(.text+0x16b9e): undefined reference to `glXGetProcAddressARB'
glew.o: In function `_glewInit_GLX_VERSION_1_3':
glew.c:(.text+0x16be5): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x16c1a): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x16c4f): undefined reference to `glXGetProcAddressARB'
glew.c:(.text+0x16c84): undefined reference to `glXGetProcAddressARB'
glew.o:glew.c:(.text+0x16cb9): more undefined references to `glXGetProcAddressARB' follow
glew.o: In function `glxewGetExtension':
glew.c:(.text+0x17f4b): undefined reference to `glXGetClientString'
glew.o: In function `glxewContextInit':
glew.c:(.text+0x18029): undefined reference to `glXQueryVersion'
collect2: ld returned 1 exit status


A google search can probably track down where these guys are defined. But it happens that I know these guys are defined in the GL library for my platform. glX is for X11 whereas you would be dealing with wgl for windows.

Code:
g++ main.o glew.o -o main -lGL


Seems to have worked. Let's run it:

Code:
./main
Can't open file 'vshader.txt' for reading
Can't open file 'fshader.txt' for reading
zsh: segmentation fault  ./main


This is where I give up :D

Of course reading the official manual for the software is always recommended, rather than just jumping in like I did. I tend to only read the manual once things go wrong.

_________________
Heard in #gpwiki: <wzl> is there some serious grammar fail in your line or am i just too intelligent for your logic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 19, 2009 7:40 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3807
Location: South Africa
:lol Thank you for those long posts sdw, good reads and good humour :)

I probably will be doing this as a career, and we're busy learning about compilers right now in uni. We haven't gotten to the linking part yet though, so it's still a nebulous mystery to me at the moment. We've covered computer architecture, assembler and operating systems, which is just to say I know something about them. I've also looked through the assembly of programs and messed around with them to see what it does, like finding the right JE to change into JNE on an easy crackme :P But specific arcane knowledge of C++ and C is very low. I know about the .o files being object code which has to get linked together into the final executable, but don't know anything about the mechanism by which it happens. I also knew that the name decorating happened from reading Thinking in C++, but didn't know what a decorated name might look like. Basically, in most of these areas, I know enough to be able to partially understand and thoroughly confuse myself. I guess (and hope) that confusion is one of the first steps to learning though.

Quote:
This does not make much sense to me. My best guess is that you're not compiling glew.c in with your project.

I checked Codeblock's obj folder and there's a glew.o and a main.o there, so I think it is compiling the glew.c. The glew.o is 781KB. Also, it's listed in the project source files, so must surely be part of C::B's make process.

There is still so much stuff I need to learn that I haven't learnt from uni. Amazon.com is going to be very happy when I finish my studies and start sending large amounts of cash their way for all the books I'll need.

I think I'm going to boot knoppix again just now and try to compile in there again, I'll follow your example and see what happens.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group