0

Where do I get gtk-win32-3.0.lib from?

I am trying to use GTK3 with Code::Blocks. The thing is initially when I was trying to create a GTK project, it gave me an error that it can't find gtk.h. I then edited the wizard script and changed gtk-2.0 to gtk-3.0 as seen in an answer on Stack Overflow.

After doing that, it gave me an error cannot find gtk-win32-2.0. I changed this to gtk-win32-3.0 in the script but the error still persists.

I have both the files gtk.h and gtk-win32-3.0 in the GTK directory. I crosschecked this many times. Can someone help me with this?

I just discovered that I don't have a file 'gtk-win32-3.0.lib` in the gtk\lib directory. I manually created one in the directory and now Code::Blocks lets me create a project. I still don't know what should be present inside the library file.

Edit: The project gets created after I added a blank file named gtk-win32-3.0.lib in the expected directory but the files doesn't get compiled.

Current error:error: ld returned 1 exit status Didn't get more details regarding the error.

The same program gets compiled when used outside the project as an individual source file.

Mathews Mathai
  • 1,707
  • 13
  • 31
  • I don't know Code::Blocks well, but in some IDEs, I've seen that you have to declare - normally in some Project dialog - which are the libraries you have in use in your project - possibly twice: once for the include files, and once for actual libraries. So, though gtk.h is in your source file, you may have to explicitly declare the path in your project definition. (also note that, if in C/C++, you have to declare `#include `) – jcoppens Aug 02 '16 at 16:00
  • @jcoppens It doesn't even let me create a project file. – Mathews Mathai Aug 02 '16 at 16:04
  • @jcoppens updated the post. – Mathews Mathai Aug 03 '16 at 16:16

1 Answers1

1

I just noticed I still have code::blocks installed (version 13.12). Note that I am on Linux. I just clicked on File|New|Project.

First step: File

I then selected the new project to be a Gtk project, and most everything was ready.

Project from template

You'll have to fill in a project name (Test99 in the screenshot) and a location.

GTK Project

I suspect you do need to have the gcc compiler installed, and of course the Gtk libraries. You'll also need pkg-config, which is necessary for configuration.

By default, the new project was configured to be a gtk-2 project. But you can change that by changing the part of the includes. Right click on the project name in the left panel (Test99), and select Properties. In Properties, select Project Build Options (don't be tempted to select Options instead of Properties in the previous step. I don't know why, but they're different!)

Linker Options

Select Linker Options, and you should see pkg-config gtk+-2.0 --libs with 'back-ticks' around it. Changing 2.0 into 3.0 should link with the libraries.

Compiler options

Go to Compiler Settings, then Other Options and again, you will find a similar entry pkg-config gtk+-2.0 --cflags (also with backticks). This detects where the gtk.h file lives. (Also change 2.0 to 3.0)

That should be it. This may not be the latest version of code::blocks. If you encounter problems, yell!

jcoppens
  • 5,306
  • 6
  • 27
  • 47
  • In my case, it doesn't move ahead from the GTK+ project dialogue box. It refuses to accept the directory for gtk files. I am on windows. I have set up gcc and gtk on my system and I have also set up the environment variables. Code::Blocks lets me create a C source file and use gtk functions in it but it doesn't let me create a gtk project. I have gtk+3 installed while the script in Code::Blocks looks for gtk+2. I edited the script and then it says- "gtk-Win32-3.0" not found. But this file is present in the library. `Note: The stand alone C source files work pretty well` – Mathews Mathai Aug 03 '16 at 15:16
  • Something's wrong with the Code::Blocks script. Is there anyway I could create a gtk project on eclipse? or Dev C++ ? Things get easier with linux but then I am aiming at creating something for windows so I prefer to work on windows (though GTK GUIs are pretty cross platform) – Mathews Mathai Aug 03 '16 at 15:20
  • 1
    Do you have `pkg-config` (or `pkgconfig` depending on where you get your software)? This utility lets `code::blocks` interrogate where the libraries are installed. Try `pkg-config --modversion gtk+-3.0` from a terminal. You do have `#include ` in your code (note the `gtk/`)? – jcoppens Aug 03 '16 at 15:21
  • I have tested all of that. Tested it even now on cmd. Also tried this on the windows command prompt- `pkg-config --cflags --libs gtk+-3.0 ` and worked as expected. Gtk is well set up on my system because standalone C source files containing gtk functions work pretty well on Code::Blocks. But it doesn't let me create a project. – Mathews Mathai Aug 03 '16 at 15:22
  • Yes. I used `#include ` and I have pkg-config. Code::Blocks is recognising the gtk libraries since I have added the path to the environment variables but it isn't letting me create a project. I can create a stand alone C source file and include gtk functions in it. – Mathews Mathai Aug 03 '16 at 15:32
  • I just discovered that I don't have a file 'gtk-win32-3.0.lib` in the `gtk\lib` directory. I manually created one in the directory and now Code::Blocks lets me create a project. I still don't know what should be present inside the library file. – Mathews Mathai Aug 03 '16 at 15:42
  • 1
    I found [an interesting reference](http://stackoverflow.com/questions/20128380/error3error-lnk1104-cannot-open-file-gtk-3-lib) to `pkg-config` generating requests for non-necessary libraries. Also check the comments. And another question. Did you enter a path for the project to a location which is accessible to you? – jcoppens Aug 03 '16 at 15:55
  • This file 'gtk-win32-3.0.lib` was not present and Code::Blocks was looking for this. I created this manually and it lets me create a project now. But there should be some content in that file. I just created a blank one. – Mathews Mathai Aug 03 '16 at 16:03
  • So, you have a project. What happens if you compile now? Can you paste the compile output somewhere (maybe in you original question)? – jcoppens Aug 03 '16 at 16:11
  • Ok. This seems to be an execution problem of gcc. Did you check if gcc actually works? And does [this article](http://stackoverflow.com/questions/7991561/c-program-does-not-run-in-codeblocks) help? – jcoppens Aug 03 '16 at 16:28
  • Yes. I compiled regular C programs successfully on thee command prompt. The same program gets executed when not in the project and when compiled as an individual source file. – Mathews Mathai Aug 03 '16 at 16:30
  • Please check previous comment - I edited it after your confirmation. Check in Settings if the configuration of the toolchain (gcc/g++) is correct. – jcoppens Aug 03 '16 at 16:36
  • Yes. gcc is working perfect! Normal C programs are getting compiled. – Mathews Mathai Aug 03 '16 at 17:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/119036/discussion-between-mathews-mathai-and-jcoppens). – Mathews Mathai Aug 03 '16 at 17:40