How to build a GTK3 application with msys2? - gtk

I had installed msys2 and mingw-gcc, gtk3 package.
pacman -S mingw-w64-i686-toolchain
pacman -S mingw-w64-i686-gtk3
Then I tried to build a test code.
// main.c
#include <stdio.h>
#include <gtk\gtk.h>
int main()
{
printf("hello, msys2!");
return 0;
}
but this test code wasn't build with error.
main.c:2:21: fatal error: gtk\gtk.h: No such file or directory
I checked gtk.h's location and fixed and rebuilded.
// #include <gtk\gtk.h> -> #include <gtk-3.0\gtk\gtk.h>
C:/msys32/mingw32/include/gtk-3.0/gtk/gtk.h:30:21: fatal error: gdk/gdk.h: No such file or directory
I guess there is my mistake i dont know.

go gtk3 tutorial site.
and read gcc option.
gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`

At the beginning (compiling with MSYS2) I have the same problem and procedure as suggested using the following command (or something like that):
gcc `pkg-config --cflags gtk+-3.0` hello.c -o hello `pkg-config --libs gtk+-3.0`
However the error message remained... So after some internet research I discovery that I have to type (in my case) the following command:
export PKG_CONFIG_PATH=/mingw32/lib/pkgconfig
or
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig
And them use the compile command previously quoted and then things start to running better and I was able to compile and run my programs.
The sad thing (one of many) is that I have to do this procedure every time I restart the MSYS2. I'm taking suggestions for not have to do it anymore :-)
And the other sad thing is in the fact that after reinstall a new version of MSYS2 (and Codeblocks in my computer) I still able to compile programs, however they are not running due an error with the zlib1.dll.
The message is
"The procedure entry point inflateReset2 could not be located in
the dynamic link library zlib1.dll"

Related

pkg-config giving me strange error involving gtk+-3.0 on linux mint

So when I run:
gcc `pkg-config --cflags --libs gtk+-3.0` -o program-name code.cpp
to compile my program against the gtk3 libraries, I get the following error:
Package 'xfixes' requires 'fixesproto >= 6.0' but version of fixesproto is 5.0
This error only shows up when trying to compile against gtk+3.0, not against
any of the other libraries with compatible .pc files for pkg-config.
I installed gtk+3.0 libraries through synaptic package manager, so I assume
everything needed was installed, so I don't really have any idea what this
error message means, or how to fix it.

System.DllNotFoundException in pocketsphinx swig Unity windows build

Goal:
Obtain a wrapper dll to use pocketsphinx in a Unity project in Windows.
Problem:
When running the test program, I get an annoying System.DllNotFoundException even though the .so file is in the same directory as the mono program.
Setup and attempted actions:
For starters, I am using Cygwin. I was able to build absolutely everything, sphinxbase and pocketsphinx no problem. Then I went into the swig/csharp directory and attempted make. It does make, a .so file is created. I am using the default Makefile and make in cygwin. Rules 1-3 run perfectly fine, building, linking and everything. So does the pocketsphinx_continuous test.
pocketsphinx.c: ../pocketsphinx.i
mkdir -p gen
swig -I.. -I../../../sphinxbase/swig -I../include -I../../sphinxbase/include \
-csharp \
-dllimport "libpocketsphinxwrap.so" \
-namespace "Pocketsphinx" -o sphinxbase.c \
-outdir gen ../../../sphinxbase/swig/sphinxbase.i
swig -I.. -I../../../sphinxbase/swig -I../include -I../../sphinxbase/include \
-csharp \
-dllimport "libpocketsphinxwrap.so" \
-namespace "Pocketsphinx" -o pocketsphinx.c \
-outdir gen ../pocketsphinx.i
libpocketsphinxwrap.so: pocketsphinx.c
gcc -fPIC pocketsphinx.c sphinxbase.c `pkg-config --libs --cflags pocketsphinx` -shared -o $#
test.exe: libpocketsphinxwrap.so
mcs test.cs gen/*.cs
run: test.exe
MONO_LOG_LEVEL=debug mono test.exe
clean:
rm -rf gen
rm -f libpocketsphinxwrap.so
rm -f pocketsphinx.c
rm -f sphinxbase.c
rm -f test.exe
.PHONY: run clean
When attempting mono test.exe - the following happens:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Pocketsphinx.PocketSphinxPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: libpocketsphinxwrap.so
The .so is in the same directory as the test.exe file and is certainly being looked at because when running mono with MONO_LOG_LEVEL=debug, the output is:
Mono: DllImport error loading library 'C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll': 'The system cannot find the file specified.
Many times over and over.
Any help will be greatly appreciated. Again, I need a libpocketsphinx.so x86_64 for windows in Unity to interop with the C# files.
Thanks.
--- edit - added relevant snippet. test.cs just calls this method from the wrapper data structure. These files were all generated by SWIG.
[global::System.Runtime.InteropServices.DllImport("libpocketsphinxwrap.so", EntryPoint="CSharp_Pocketsphinx_Decoder_GetConfig")]
public static extern global::System.IntPtr Decoder_GetConfig(global::System.Runtime.InteropServices.HandleRef jarg1);
I doubt Cygwin DLL is compatible with Mono/Unity. You need to create DLL in Visual Studio, then it will work.
Why do you test the so file with mono, while it is actually used in Unity?
Mono: DllImport error loading library 'C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll': 'The system cannot find the file specified.
If file libpocketsphinxwrap.so does exist in C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\, try rename libpocketsphinxwrap.so to libpocketsphinxwrap.so.dll so mono can find it.
See also mono pinvoke: library names and DllNotfoundException.
You can try build pocketsphinx with Visual Studio since it is offically supported.
BTW, I'd rather write the C# wrapper myself instead of using SWIG since there are many traps in P/Invoke and I don't think SWIG can handle all of them.

GCC C++ Linker section on FC13

I am trying to get OpenGL and Glut running on Eclipse Linux FC13.
After spending two days on it, I admit that help is needed. On FC13 Eclipse, I see
/usr/include/GL and /usr/include/SDL -- so the libs are there. I started Eclipse, and then tried to run a simple program on it, just like suggested here. However, two things were missing in those steps:
Callisto could not be installed --
nothing was found from the
repository
GCC C++ Linker is not found anywhere
for Eclipse 3.5.2.
When trying to run the program, I see this error:
Program does not exist
and sometimes
Binary not found
If I just run the "hello world" it works, but otherwise, those errors happen every time I try to include glut gl or sdl commands.
Here is an excerpt from the compiler error:
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o tw.o tw.cpp
tw.cpp: In function ‘void main_loop_function()’:
g++ -o tw tw.o
Yes, apparently the compiler is not able to see the glu, gl, sdl and glut libraries.
Some suggestion on how to fix?
You have to tell the compiler that your program uses additional libraries.
Use the -l argument
g++ -O2 -g -Wall -fmessage-length=0 -lglut -lGL -lGLU -lX11 -c -o tw.o tw.cpp
This should help against unsatisfied link errors.
You can set these in the properties of your Project.
Properties->c/c++ Build->Settings->Tool Settings->Linker
Check if the compiler is able to find the appropriate header files or not. If not, you are sure to get compiler errors. Try using the -I option to set the appropriate paths.
Once you've fixed that, check if there are any linker errors (undefined symbols/references or the sort). If you do: Try to set the library paths using the -L option and ask the compiler to link in the specific libraries by using the -l option. Note that the latter expects something like -lmath where in reality the library being linked in is actually called libmath.so or libmath.a (as the case may be).

Gtk-WARNING Could not find signal handler on netbeans

I'm building an interface using glade and gtk programming on c using netbeans. I've set up my project following this tutorial. I even added libgmodule2-0.so and libglib2-0.so to the linker options of netbeans. When I run i get the warning Gtk-WARNING Could not find signal handle. When I close the mainwindow nothing happens (this is where my signal should be caught)
If I compile my program like this (not using netbeans)
gcc -o tut main.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0)
it works fine. When I close the mainwindow it closes.
I like using IDEs because all the features I get (specially debugging). Any suggestion for this problem?
I think that adding libgmodule2-0.so and libglib2-0.so to the linker options is not enough. Run the command pkg-config --cflags gtk+-2.0 gmodule-2.0 in your terminal and see what it says. Add any directories listed with -I to the include directories of your NetBeans project, and add any other flags to the C compiler options.
Then run pkg-config --libs gtk+-2.0 gmodule-2.0 in your terminal and add anything listed there to the linker options.

How to get GCC linker command?

How can I get the command line GCC uses to invoke ld?
I have a problem for an AVR target where GCC apparently adds a linker option which I am trying to override, so I would like to look at the exact options GCC uses for ld.
Use gcc -v to see what commands it runs. As in,
gcc -v -o hello hello.c
This will print a lot of output, including the linker command. The actual output depends on the platform, but the linking command should be near the end. Alternatively, use
gcc -### -o hello hello.c
This is like -v, but does not actually run any commands and quotes the options.
Another option is
gcc -dumpspecs
Look for the entry for link.
The above command line flags are listed in gcc --help and explained on the man page. Here's GCC documentation for the spec files.