Pelles C forum

C language => Beginner questions => Topic started by: hellohowru? on April 29, 2007, 11:29:51 AM

Title: Please help 2d plotter!!! T_T
Post by: hellohowru? on April 29, 2007, 11:29:51 AM
I dont really know what im doing. Im trying to use the 2d plotter in from http://g2.sourceforge.net. I downloaded it and i used this code in my mainprogram.c:



#include <stdio.h>
#include <math.h>
#include "g2.h"
#include "g2_X11.h"
#define xsize  3
#define ysize  4

int main(){

   const int dev = g2_open_X11(xsize,ysize);

   g2_close(dev);

   return 0;
}

then i added the .h files g2.h & g2_X11.h it compiled but it would not run it keeped on crying about:
POLINK: error: Unresolved external symbol '_g2_open_X11'
POLINK: error: Unresolved external symbol '_g2_close'
POLINk: fatal error: 2 unresolved external(s)

I dont know if im using the program right. I basically copied and pasted the source codes for g2.h and g2_X11.h and saved them into my project. Do i have to extract files or something? I dont know how to do that. I just want to be able to graph in C!!! :-[ Is that so much to ask? Please i will be forever greatfull if some one can help!
Title: Re: Please help 2d plotter!!! T_T
Post by: fussl on April 29, 2007, 01:06:33 PM
looks like, g2 is a external library, you need.
Title: Re: Please help 2d plotter!!! T_T
Post by: fussl on May 01, 2007, 07:16:18 AM
if you are new to c, it might be a job too big, getting the g2 libraray running in pelles-c.

first qou need to learn,
- basic c,
- linking programs,
- using dynamic link librarys in windows,
- whats unix like environments?(cygwin & mingw),
- and so on...

please take a look in our tips & tricks forum section and the faq section. there i found links to manuals and dokumentations.
also give google a chance, please.

at all you will need approx. some weeks to learn all you need.

Title: Re: Please help 2d plotter!!! T_T
Post by: Madmanguruman on May 08, 2007, 06:16:56 PM
You need to first compile the g2 library, either a static (.lib) or dynamic (.dll) version from the sources that you downloaded.

After this, you can start using the library.

Note that if your program is for Windows, I'd follow the scheme outlined in simple_win32.c (i.e. include g2_win32, and don't include anything for X11):

Code: [Select]
#include <stdio.h>
#include <g2.h>
#include <g2_win32.h>

int main()
{
    int d;
    d=g2_open_win32(100, 100, "simple_win32", 0);
    g2_line(d, 10, 10, 90, 90);
    getchar();
    return 0;
}

Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 23, 2007, 11:20:47 AM
To let the compiler find a definition file (.h) you don't have to include it in the project files, but you have to specify the directory where it is stored. To do this select "project options" from the "project" menu, choose the tab "folders", in the dialog select the type "includes", than press the button "New Folder" and select the folder where is the file "g2.h".
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 24, 2007, 07:58:32 AM
Thanks, it complied but now it wont run -_-

It gave me these errors:
POLINK: error: Unresolved external symbol '_g2_open_win32'.
POLINK: error: Unresolved external symbol '_g2_line'.
POLINK: fatal error: 2 unresolved external(s).
*** Error code: 1 ***
Done.

Why does it not run? I dont know what these errors mean.
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 24, 2007, 11:19:48 AM
If you're building the g2.dll define the symbols WIN32, G2DLL, MAKEDLL (from project menu in the compiler tabs add these symbols in the "define preprocessor symbols" editbox).
If you still have problems post the project file (extension .ppj).
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 24, 2007, 10:32:06 PM
well, im still having problems. It still reads the same errors but now theres a bunch of errors poping out when i try compiling the program:

C:\Documents and Settings\Administrator\Desktop\pleasework\g2-0.72\src\g2.h(183): warning #2016: Extended attribute 'dllexport' requires option /Ze; ignored.

I attached my prj:
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 25, 2007, 07:41:59 PM
I think it's better to give you the working library with two demo's.
I modified original sources to avoid the use of an additional resource library.
I also corrected many ansi C compliance problems in the sources.
Look at the code and project settings and try to understand the corrections.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 25, 2007, 10:43:01 PM
Grrr.... more problems. I cant get the program running. It gives me these errors now:

Error reading from file 'g2.anim.c'.
The system cannot find the file specified

I downloaded your attachment, then i opened the pelles C icon and pressed execute button but it gave me this error. Why does this happen?
Title: Re: Please help 2d plotter!!! T_T
Post by: DMac on July 25, 2007, 11:46:47 PM
Frankies projects are configured to look for stuff where he has Pelles installed.

I fixed it to look to the default locations.

1.  Unzip this into C:\Program Files\PellesC\Projects

2.  build the dll.

3.  put a copy of the dll in the demo folder.

run the demo.

Good luck.

David M.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 26, 2007, 01:24:13 AM
i almost got it to work. What do you mean by putting a copy of the dll into the demo folder? Do you mean copying the dll folder and putting it in the demo folders? or is it some other file?

Error message: The application failed to start because dll was not found.
Title: Re: Please help 2d plotter!!! T_T
Post by: DMac on July 26, 2007, 01:43:08 AM
Look in:

"g2_workspace\g2_dll" folder for the file g2_dll.dll.

If you built this project the file should be there.

copy it to the folder:

"g2_workspace\g2demo"

The demo will now be able to find the dll and should run.

regards,

David M.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 26, 2007, 05:56:45 AM
I must not be building correctly because i cant find the file. I thought I just needed to open the project and press the build button but I still cant run it or find the file.
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 26, 2007, 11:32:30 AM
The way the paths are used by the IDE is somewhat annoying I should ask Pelle to modify the behaviour to make projects more portable.
Anyway to let demo work you need that the dll is available, so first of all build the g2_dll project, than you can build the demo's.
To run the demo's is required the presence of the g2_dll.dll in the folder of the executable, so you must copy the library in the directory of the demo's.
Title: Re: Please help 2d plotter!!! T_T
Post by: JohnF on July 26, 2007, 11:54:44 AM
The way the paths are used by the IDE is somewhat annoying I should ask Pelle to modify the behaviour to make projects more portable.

One way to simplify things would be to have only one place to set the folders, say under the Tools/Options dialog, all the necessary includes could be done there, no real need to have separate settings for projects.

Or, if one needs a header from another folder write the appropriate line in the code - if one has provided the necessary directory structure of course.

Example:
#include "Neat.h"
#include "..\View\View.h"

John
Title: Re: Please help 2d plotter!!! T_T
Post by: TimoVJL on July 26, 2007, 02:17:29 PM
g2_anim.ppj and g2_demo.ppj should use relative INCLUDE and LIB paths for g2 files.
Like ..\g2_dll
Code: [Select]
INCLUDE = C:\Program Files\PellesC\Include;C:\Program Files\PellesC\Include\Win;C:\Program Files\PellesC\Include\Win\gl;..\g2_dll#
LIB = C:\Program Files\PellesC\LIB;C:\Program Files\PellesC\LIB\WIN;..\g2_dll#
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 26, 2007, 09:04:14 PM
I still dont know what you mean by: "build the g2_dll project" Do i need to create a new project and call it g2_dll?... how do you build? I cant just right click and press build or just open up pelles and press the build button. The file g2_dll.dll does not exsist, theres a g2_dll.LIB and .ppx but theres no .dll.

Please show me how to "build" the g2_dll project.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 26, 2007, 10:09:53 PM
grrr... now i messed up one of the projects. I opened up g2_dll.ppj and right clicked some source code looking  thing that said g2_dll.dll in bold letters and added the files to one of the demos and hit the compile button and a hole bunch of errors came up.

I'm guessing that is not the way to build projects then.
Title: Re: Please help 2d plotter!!! T_T
Post by: TimoVJL on July 26, 2007, 11:02:52 PM
One way to build dll is to load g2_dll.prj and press Ctrl+B.

Title: Re: Please help 2d plotter!!! T_T
Post by: DMac on July 26, 2007, 11:53:02 PM
Ok Let's take this one step at at time.

Since I don't know what you did to the demo I suggest doing the following:

1.  Open the "C:\Program Files\PellesC\Projects" folder and delete the "g2_workspace" folder located there.

2.  Go to my previous post and download the the g2_workspace.zip attatchment again.

3.  Unzip this into C:\Program Files\PellesC\Projects.

4.  Open the "C:\Program Files\PellesC\Projects\g2_workspace\g2_dll" folder.

5.  Find and click on the g2_dll.ppj.

6.  Now that the project is opened in Pelles IDE click on the "Project" menu.

7.  From the drop down select "Build g2_dll."

     At this point Pelles will compile the source into g2_dll.dll.

8.  Once the build is finished Open "C:\Program Files\PellesC\Projects\g2_workspace\g2_dll" folder.

9.  Find the file "g2_dll.dll." and copy it.

10.  Open "C:\Program Files\PellesC\Projects\g2_workspace\g2demo folder" and paste g2_dll.dll there.

11.  Find and click on the g2demo.ppj.

12.  Now that the project is opened in Pelles IDE click on the "Project" menu.

13.  From the drop down select "Execute g2demo.exe"

And there you have it 13 steps to success.

David M.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 27, 2007, 03:45:24 AM
thx but there is still a problem it wont let me build it says:

Could not find <windos.h>

do i just add it to library? i havent tryed it yet.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 27, 2007, 03:55:43 AM
never mind i added the stuff i needed to the library. Do i have to add .dll too or does this progrm take long to load becuase it executed fine but it was taking long so i closed it and then it crashed.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 27, 2007, 04:00:09 AM
a pop up menu pops out when i execute it and it says: dll process attach.
Is that bad or good? Do i need to give it some time? I gave the program almost an hr to load but nothing appears, there has to be something wrong. This program is not responding.
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 27, 2007, 12:19:42 PM
The program works exactly as you have seen.
The popups are coded in the library to inform you that you're attaching detaching from the library. If you don't like them comment them out from the code and recompile the library.
The program crash: yes it's not so well coded, if you close the graphical window the consolle crashes! Try to close the console window and it will not crash.
G2 needs some fixing to work properly, and this is not my top interest at the moment, if you're a programmer study it and make your corrections, if you want just a graphical tool this way could be very exhausting, you have to learn programming to use it  ::)!!


John, for the IDE's paths I was wondering about a macro like $(WIN_INC) that the IDE automatically translates to the default installation paths, in this case the 'standard places' are removed from the include and library folders configuration. If you need more paths you can continue to add them as you do now. You're right about the use of paths in the includes, but it is a problem when you import a project from others like g2 or sqlite, etc. You have to manually correct all modules.
Another problem is the project archiving that retains in the zip the absolute path, once again you cannot install an archived project in a directory different from the original.
Title: Re: Please help 2d plotter!!! T_T
Post by: JohnF on July 27, 2007, 01:21:19 PM
John, for the IDE's paths I was wondering about a macro like $(WIN_INC) that the IDE automatically translates to the default installation paths, in this case the 'standard places' are removed from the include and library folders configuration. If you need more paths you can continue to add them as you do now. You're right about the use of paths in the includes, but it is a problem when you import a project from others like g2 or sqlite, etc. You have to manually correct all modules.
Another problem is the project archiving that retains in the zip the absolute path, once again you cannot install an archived project in a directory different from the original.

I have no objections to a macro, of course the decision is Pelle's to make.

As for adjusting other peoples projects, I guess that will always be the case as different compilers have slightly different ways of doing things. The current problem is that the OP is trying to run before he can walk. Hope he learns from the experience.

Are you sure about the project archiving? I just tried it and it seems ok to me.

Anyway, lets see what Pelle has to say on the matter.

John
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 27, 2007, 01:48:24 PM
Are you sure about the project archiving? I just tried it and it seems ok to me.

Yes but only for workspaces, for a single project it uses relative paths, probably he's trying to retain libraries and includes path definition. This is probably because when you add folders for libraries or includes he stores absolute paths.
Title: Re: Please help 2d plotter!!! T_T
Post by: JohnF on July 27, 2007, 06:35:42 PM
Are you sure about the project archiving? I just tried it and it seems ok to me.

Yes but only for workspaces, for a single project it uses relative paths, probably he's trying to retain libraries and includes path definition. This is probably because when you add folders for libraries or includes he stores absolute paths.

Absolute paths make life more difficult - maybe Pelle will read this thread.

John
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 28, 2007, 07:11:52 AM
The program crash: yes it's not so well coded, if you close the graphical window the consolle crashes! Try to close the console window and it will not crash.

You claim that there is a graphical window here but i only get a console window and the popup that says dll message 1. When i execute the program i get no graphical window. Do i need to add something else? I've tryed to execute another program (something call arc..) and i get the same thing: The empty console and the little popup that says dll message 1. Intuition tell me i need to see an arc some where, since this is after all a graphical program.

For the other demo, i read the code its supposed to print out "random walk" then create the random walk but the console does nothing and there is no graphics window.
Title: Re: Please help 2d plotter!!! T_T
Post by: frankie on July 30, 2007, 06:03:25 PM
The windows that pops up contains a button, if you don't press that button the program does'nt continue.
Title: Re: Please help 2d plotter!!! T_T
Post by: DMac on July 30, 2007, 06:37:50 PM
When the console window opens up you just press "Enter" until the graphical window opens up.  You continue to press enter untill the demo exits.  The demo directory will then be full of graphical image files.

By studying the demo's code you can learn some of the methods presented and then you can apply them in your application.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 30, 2007, 09:44:48 PM
so how many times and for how long do i need to be pressing enter? When the console and the pop up with the button shows up, as soon as i press the button the program stops responding. and i cant hit enter in the console window, it just does nothing. Is there something wrong w/ my computer? Do i need to download something else to view the graphics. I don't understand why the program immediately stops running once i press the button. I checked by pressing ctrl-alt-delete and it shows that the dll message 1 program is not responding.
Title: Re: Please help 2d plotter!!! T_T
Post by: hellohowru? on July 30, 2007, 10:27:35 PM
why is there such a high probability of this program to crash. I still haven't runned this program yet but now a second pop up came up and the console started saying something and then it the program stopped responding again. But i re-executed like 10 times and it still stops responding in like the beginning of the execution.