Hey everyone. I'm trying to use the g2 library in CodeBlocks but I can't seem to get it properly installed. Can somebody please explain me what to do, step by step? Best regards

Some questions:

Do you mean this g2? What does "properly installed" mean to you? Do you want to compile it yourself, or just have the library available to use? What operating system are you using?

That very same g2, exactly! It is possible to use it with any Microsoft OS, right? I've used it in the past, for academic purposes, on Linux. I'd like to be able to have library available for me to use. I've tried to follow the instructions but the downloaded file does not contain a .lib file, for instance. And I really have no clue what to do, I won't hide that, I'm quite a newbie at this. Thanks for your quick reply, anyway!

Ah, on the Linux machines you just get the package and configure/build from source. Not so simple for Windows.

It looks like the source package includes some old Visual Studio files, so the easiest thing would be to build the 'g2' and 'g2dll' projects... if you can. I think they're VS6 projects, so if you happen to have VS6, do that.

Otherwise, I think cooking up a Code::Blocks project based on the VS6 ones shouldn't be too hard.

Are you using the MinGW/GCC that comes with some C::B distributions?

Yes, I am.

Regarding VS6, I don't have it, unfortunately. But I do own a trial version of VS 2012, not sure if that'd do the trick. When I tried to open the "g2" and "g2dll" projects with VS2012, it failed to convert the project.

If I were to build it on C::B, how exactly should I proceed? Unless you've got any other tips, ofc

Let's see if we can just build it with C::B; that seems simplest to me.

  1. Create a new project. Use the empty project template.
  2. Go to project properties, build targets tab.
  3. Change type to static or dynamic library (do for both Debug and Release)
  4. Open g2.dsp in a text editor
  5. Go to the end, where there are a bunch of lines starting with "SOURCE="
  6. Add all of these files to your C::B project
  7. Try to build the project; it won't work.

Fixing the errors partly depends on what you need from g2:

  • Do you want a static or dynamic library?
  • Do you want GD support (PNG and JPEG)?

Alright, I've tried everything said above and I get alot of undefined referenced functions.

Regarding you two questions, GD support would be much appreciated for my project development. Now I'm kind of embarrased to ask, but I do not know the difference between a static or a dynamic library..

tried everything said above and I get alot of undefined referenced functions

That's expected :)

Make a note of the reference names; they usually refer to functions in a library the compiler hasn't been told about.

In this case, I know there are some Windows GDI functions that g2 uses. To fix these errors, go to your project's build options, and in the linker settings section, add "gdi32" to the link libraries list. No path needed.

GD support would be much appreciated for my project development.

Do you already have GD on your system? If not, go download a binary.

I think that's where any other undefined references will be found. You'll have to add the GD library in the linker settings like we did for GDI32, but it isn't a system library, so you'll have to browse for it and keep the path information.

the difference between a static or a dynamic library

Static libraries (*.lib or *.a) contain code that is copied into your program when it is built.

Dynamic libraries (*.dll or *.so) are kept separate, and may be shared between different programs.

Further reading:

http://en.wikipedia.org/wiki/Static_library
http://en.wikipedia.org/wiki/Dynamic_loading

Thanks for all the information provided :)

I'm pretty sure I can manage the GD part now, thanks to your tips.

As for the g2 library, it has been built with no errors, fortunately :) how will I be able to run it from any new program I write?

Awesome. Just add the g2 library you built to the linker settings of your project like you did for gd. Then include "g2.h" and knock yourself out :)

everything's is aaalmost done and I appreciate your effort in solving this problem of mine. Yet, everytime I try to run the program, it keeps saying g2.dll is missing.

Also related, is X11 a different library from g2? Isn't it included in g2? Or isn't it a library at all? I was looking at my old code (the one I used back in Linux) and so I used some of it to test g2 in Windows. And there are some functions he is not recognizing, even though I added the respective .c files to C::B

g2.dll is missing

Ah, sorry, forgot. If you built g2 as a static library, C::B will name the output "libg2.a" unless you changed it. You have to link to that file directly.

I think it wants "g2" to be a DLL if you leave off the extension.

is X11 a different library from g2?

It's the GUI system for many *nix-type OSes. Windows doesn't care.

And there are some functions he is not recognizing

Are these X11 API calls? Or something else?

looking at my old code (the one I used back in Linux)

You may have to rewrite parts of your old code to work on a Windows machine.

If you want to use a Linux-like environment, you might also look into Cygwin.

Once again, thanks :) The .dll issue has been solved.

Regarding X11, it was actually a simple X11 function, g2_open_X11.
Any clue?

Can't thank you enough for everything you've done so far, anyways!

When I use Win32 I get no more undefined references, thank god :)

However, nothing happens.. Shouldn't a new window be openned?

When I use Win32 I get no more undefined references, thank god :)

However, nothing happens.. Shouldn't a new window be openned?

actually, now it opens a windows, but it says "Could not load g2 resource DLL. Menu and Icon are disabled" :/

Hm. It's looking for g2res.dll. I haven't done this myself, but I think C::B knows what to do with .RC files. Try making a new DLL project with the files in g2res.dsp and see if that builds.

I did and everything works now, the window opens, doesn't ask me for anything. But no command works. I mean, it does open a window according to my size specifications, but everything I try to print on that window (let it be circles, squares, rectangles) just doesn't pop up..

Nope nope nope. Got it to work :D forgot to include "g2.h" haha xD

Again, thanks for your help! Could have never done it without your support!

Are you calling g2_flush for your device?

ETA: Oops, didn't see your latest post. Glad it's working!

Edited 3 Years Ago by gusano79

This question has already been answered. Start a new discussion instead.