Errors in creating Python interface for multiple C++ files in a shared library - boost-python

I have two c++ files named as "animal.cpp" and "zoo.cpp". These files are compiled as a shared library "zoo.so". I want to access the functions defined in these files from Python interpreter.
However, I am getting errors. I tried to do some changes but getting different kind of errors. I hope expert of Boost-Python may guide me in solving these issues.
Note: To keep the problem simple, I have not used classes, otherwise I could easily make classes of "animal" and "zoo".
I want to access both files function from Python.
Any guidance will be highly appreciated.
Thanks,
animal.cpp
+++++++++++
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string hello_animal() {
return std::string("hello, animal");
}
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string getname_animal() {
std::string input;
std::cout<<"Please enter your favorit animal name: ";
std::getline(std::cin,input);
return std::string("Your favorit animal name is: ").append(input);
}
/*
* This is a macro Boost.Python provides to signify a Python extension module.
*/
BOOST_PYTHON_MODULE(animal) {
// An established convention for using boost.python.
using namespace boost::python;
// Expose the function hello_animal().
def("hello_animal", hello_animal);
// Expose the function getname_animal().
def("getname_animal", getname_animal);
}
zoo.cpp
++++++++
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string hello_zoo() {
return std::string("hello, zoo");
}
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string getname_zoo() {
std::string input;
std::cout<<"Please enter your favorit zoo name: ";
std::getline(std::cin,input);
return std::string("Your favorit zoo name is: ").append(input);
}
/*
* This is a macro Boost.Python provides to signify a Python extension module.
*/
BOOST_PYTHON_MODULE(zoo) {
// An established convention for using boost.python.
using namespace boost::python;
// Expose the function hello_zoo().
def("hello_zoo", hello_zoo);
// Expose the function getname_zoo().
def("getname_zoo", getname_zoo);
}
I have created a shared library using following command:
g++ -shared -o zoo.so -fPIC zoo.cpp animal.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
Python Interpreter Commands and output:
import zoo
zoo.getname_zoo()
Please enter your favorit zoo name: zoo
'Your favorit zoo name is: zoo'
zoo.getname_animal()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'getname_animal'
When I make following changes in animal.cpp file, I get different error.
BOOST_PYTHON_MODULE(zoo) {
instead of
BOOST_PYTHON_MODULE(animal) {
On compilation I get following error:
[root#localhost zooexample]# g++ -shared -o zoo.so -fPIC zoo.cpp animal.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
/tmp/cci4WKrP.o: In function initzoo':
animal.cpp:(.text+0x15d): multiple definition ofinitzoo'
/tmp/cctaGDer.o:zoo.cpp:(.text+0x15d): first defined here
/tmp/cci4WKrP.o: In function init_module_zoo()':
animal.cpp:(.text+0x179): multiple definition ofinit_module_zoo()'
/tmp/cctaGDer.o:zoo.cpp:(.text+0x179): first defined here
collect2: error: ld returned 1 exit status
+++++++++++++++++++++++++++++UPDATED++++UPDATED+++++UPDATED+++++++++++++++
Considering the suggestion given by Dan for my previous issue. Now I have created a separate file pyintf.cpp containing the following code:
BOOST_PYTHON_MODULE(pyintf) {
def("hello_zoo", hello_zoo);
def("getname_zoo", getname_zoo);
def("hello_animal", hello_animal);
def("getname_animal", getname_animal);
}
but when I compile and create a shared library using the following command:
g++ -shared -o pyintf.so -fPIC pyintf.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
I get following error when I import the "pyintf" module in python.
import pyintf
Traceback (most recent call last):
File "", line 1, in
ImportError: ./pyintf.so: undefined symbol: _Z9hello_zoov
Can anyone tell what I am not doing correctly?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The issues were resolved by putting all methods which I wanted to expose in a single pyintf.cpp. The errors which I got after update were due to missing header files and source files.
Now, the above issue has resolved by adding header files (zoo.h, animal.h) and source files (zoo.cpp, animal.cpp) in the compilation command. g++ -shared -o pyintf.so -fPIC pyintf.cpp animal.h animal.cpp zoo.h zoo.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
Thanks Dan for corrections.

Related

Including edk2-libc in efi shell application

How would one approach adding support for https://github.com/tianocore/edk2-libc, say I want to include stdio and use printf in my edk2 application? I followed StdLib/Readme.txt, and am able to successfully build examples in the AppPkg, however, when I try to add StdLib to my project I get errors like these:
LibString.lib(Searching.obj) : error LNK2005: strspn already defined in LibString.lib(Searching.obj)
LibCtype.lib(CClass.obj) : error LNK2005: isspace already defined in LibCtype.lib(CClass.obj)
(...)
LibC.lib(Main.obj) : error LNK2001: unresolved external symbol main
I do have the boilerplate (!include StdLib/StdLib.inc) added to my dsc file and in inf, I have StdLib.dec added to Packages and LibC and LibStdio added to LibraryClasses. I am using VS2017 toolchain for compilation and am using edk2-stable202108 release.
I was able to achieve this using below configuration for Hello Application of AppPkg.
Hello.inf
[Defines]
INF_VERSION = 0x00010006
BASE_NAME = Hello
FILE_GUID = a912f198-7f0e-4803-b908-b757b806ec83
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 0.1
ENTRY_POINT = ShellCEntryLib
#
# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
Hello.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
StdLib/StdLib.dec
[LibraryClasses]
UefiLib
ShellCEntryLib
BaseLib
BaseMemoryLib
MemoryAllocationLib
LibStdLib
LibStdio
LibString
DevConsole
Hello.c
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <stdio.h>
int
main (
IN int Argc,
IN char **Argv
)
{
printf("Hello, world!\n");
return 0;
}
What I have understood is that LibC has ShellAppMain() defined in it which internally calls extern main(). So You need to provide definition of main() in your source just like I did in Hello.c

db2 external function ends with SQL0444N, Reason code 6, SQLSTATE 42724

I'll develop new (external) functions for DB2. My first test:
db2crypt.h
#ifndef DB2CRYPT_H
#define DB2CRYPT_H
#include <string.h>
#include <stdlib.h>
char *encryptAes(const char *source, const char *key);
#endif /* DB2CRYPT_H */
db2crypt.cpp
#include "db2crypt.h"
#include <string>
char *encryptAes(const char *source, const char *key) {
std::string test("abc");
return (char *)test.c_str();
}
is compiled without an error.
g++ -fPIC -c db2crypt.cpp -std=c++14
g++ -shared -o db2crypt db2crypt.o -L$DB2PATH -ldb2
I also copied the new file into $DB2PATH/function and made a softlink in $DB2PATH/function/unfenced.
Then I created the function with
create function aes(VARCHAR(4096), VARCHAR(4096))
SPECIFIC encryptAes
RETURNS VARCHAR(4069)
NOT FENCED
DETERMINISTIC
NO SQL
NO EXTERNAL ACTION
LANGUAGE C
RETURNS NULL ON NULL
INPUT PARAMETER STYLE SQL
EXTERNAL NAME "db2crypt!encryptAes"
which was also ok.
But when I do select db2inst1.aes('a', 'b') from SYSIBM.SYSDUMMY1
I get the error
SQL0444N Die Routine "DB2INST1.AES" (spezifischer Name "ENCRYPTAES") ist
durch Code in Bibliothek oder Pfad ".../sqllib/function/db2crypt", Funktion
"encryptAes" implementiert, auf die kein Zugriff möglich ist. Ursachencode:
"6". SQLSTATE=42724
(sorry, I don't know how to change the error output into english)
What I made wrong?
Ok, I got the answer.
Thank you at #mao, you did help me. But I also needed some other help. If someone searches for an answer:
First you have to compile with some important parameters:
g++ -m64 -fPIC -c <yourfile>.cpp -std=c++14 -I/opt/ibm/db2/V11.1/include/ -D_REENTRANT
g++ -m64 -shared -o <yourfile> <yourfile>.o -L$DB2PATH -ldb2 -Wl,-rpath,$DB2PATH/$LIB -lpthread
Second: The function declaration, you also have to add parameters for null values AND the return value can't be a function return, it has to be a parameter. Also you have to use the types which are defined in sqludf.h:
void SQL_API_FN encryptAes(SQLUDF_CHAR *source,
SQLUDF_CHAR *key,
SQLUDF_CHAR out[4096],
SQLUDF_SMALLINT *sourcenull,
SQLUDF_SMALLINT *keynull,
SQLUDF_SMALLINT *outnull,
SQLUDF_TRAIL_ARGS) {
...
}
Also, when you do C++ instead of C, you have to tell the script that it has to handle the function as C:
#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN ...

Golang procedural language for Postgresql

I'm trying to compile and run go code as Postgresql stored procedure.
My motivation is because postgresql can have excensions written in C and golang can be compiled as c-shared
So I have to files, pl.go:
package main
/*
#cgo CFLAGS: -Wall -Wpointer-arith -Wno-declaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fpic -I. -I./ -I/usr/include/postgresql/server -I/usr/include/postgresql/internal -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
#cgo LDFLAGS: -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fpic -L/usr/lib -Wl,-O1,--sort-common,--as-needed,-z,relro -Wl,--as-needed -Wl,-rpath,'/usr/lib',--enable-new-dtags -shared
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
//the return value must be allocated trough palloc
void* ret(void *val, uint64 *size) {
void *retDatum = palloc(*size);
memcpy(retDatum, val, *size);
return retDatum;
}
PG_FUNCTION_INFO_V1(plgo_func);
*/
import "C"
import "unsafe"
func main() {}
//PGVal returns the Postgresql C type from Golang type (currently implements just stringtotext)
func PGVal(val interface{}) (ret interface{}) {
var size uintptr
switch v := val.(type) {
case string:
ret = C.cstring_to_text(C.CString(v))
size = unsafe.Sizeof(ret)
default:
ret = val
size = unsafe.Sizeof(ret)
}
return C.ret(ret, (*C.uint64)(unsafe.Pointer(size)))
}
the CFLAGS and LDFLAGS i'we got from pg_config
and the file where I create the function to call, plgo.go:
package main
/*
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
*/
import "C"
//export plgo_func
func plgo_func(fcinfo *C.FunctionCallInfoData) interface{} {
return PGVal("meh")
}
the shared library is created with: go build -buildmode=c-shared -o plgo.so plgo.go pl.go && sudo cp plgo.so /usr/lib/postgresql
the function in postgresql is created with:
CREATE OR REPLACE FUNCTION public.plgo_func(integer)
RETURNS text AS
'$libdir/plgo', 'plgo_func'
LANGUAGE c IMMUTABLE STRICT
COST 1;
but when I run: psql -U root -d meh -c "select plgo_func(0)"
the server crashes with:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
EDIT: I've successfully created an golang "library" for creating stored procedures and triggers in golang plgo :)
The trick is to use version 0 calling conventions as those allow calling simple C functions without using all the fancy macros they added to version 1 calling.
You also need a single C file to invoke the PG_MODULE_MAGIC macro.
I have a working example project that does all this, might be easiest if you just copied that as a starting point.
Not sure it will let you do exactly what you want, but it does indeed work for some use cases.
https://github.com/dbudworth/gopgfuncs
Will also outline the same stuff that repo tells you...
Step 1
create a .go file with you functions and the CGO includes
package main
//#include "postgres.h"
//#include "fmgr.h"
//#include <string.h>
import "C"
import (
"log"
"sync/atomic"
)
// Functions are scoped to the db session
var counter int64
//Inc atomically increments a session local counter by a given delta
//export Inc
func Inc(delta C.int64) C.int64 {
log.Printf("Inc(%v) called", delta)
return C.int64(atomic.AddInt64(&counter, int64(delta)))
}
//AddOne adds one to the given arg and retuns it
//export AddOne
func AddOne(i C.int) C.int {
log.Printf("AddOne(%v) called", i)
return i + 1
}
func main() {
}
Step 2
create a .c file in the same directory that invokes the PG_MODULE_MAGIC macro from postgres.h, this is a requirement of all extension libraries.
Go will automatically include the C file while compiling, no special instructions are needed.
#include "postgres.h"
#include "fmgr.h"
PG_MODULE_MAGIC;
Step 3
Build your so file, trick here is to use -buildmode=c-shared
go build -buildmode=c-shared -o libMyMod.so
Step 4
Execute SQL to register your functions. Since registing an extension requires absolute paths, I prefer to pass the module on the command line to avoid making the "install.sql" script have hard coded paths in it.
PGMOD=`pwd`/libMyMod.so
psql $(DBNAME) --set=MOD=\'$(PGMOD)\' -f install.sql
Install script contains one of these statements per function you export.
It's absolutely critical you get the input / output types right as there's nothing the system can do to verify them and you may end up stomping on memory, storage, whatever. You can see the translation of pg types to c types here
create or replace function add_one(integer)
returns integer as :MOD,'AddOne'
LANGUAGE C STRICT;

Attempt to embed Perl in C on Windows

I am trying to run the following example from
Deploy a Perl Application on Windows
with a simple "Hello.pl" (just prints "Hello" to STDOUT).
It fails. The .exe file is created but does not produce any output.
Probably this is my basic misunderstanding. Could you please point me in the right direction? Btw. the "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption?
Thank you very much!
The hello.c file:
#include <EXTERN.h>
#include <perl.h>
EXTERN_C void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_Win32CORE (pTHX_ CV* cv);
EXTERN_C void
xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
newXS("Win32CORE::bootstrap", boot_Win32CORE, file);
}
static PerlInterpreter *my_perl; /*** The Perl interpreter ***/
int main(int argc, char **argv, char **env)
{
argv[1] = "-Ilib";
argv[2] = "hello.pl";
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
The perl file to build the compiler command:
#!/perl
use strict;
use warnings FATAL => qw(all);
use ExtUtils::Embed;
print "\nBuilding Hello\n";
my $gcc_cmd = join( ' ' , 'C:\Perl_516_portable\c\bin\gcc -Wall -mwindows -o K:\Scripts\Embed\Hello_3\hello K:\Scripts\Embed\Hello_3\hello.c',
&ccopts, &ldopts );
print STDOUT $gcc_cmd , "\n";
system( $gcc_cmd );
The output:
----------------------------------------------
Perl executable: C:\Perl_516_portable\perl\bin\perl.exe
Perl version : 5.16.3 / MSWin32-x86-multi-thread
C:\Perl_516_portable>perl K:\Scripts\Embed\Hello_3\building_3.pl
Building Hello
C:\Perl_516_portable\c\bin\gcc -Wall -mwindows -o K:\Scripts\Embed\Hello_3\hello K:\Scripts\Embed\Hello_3\hello.c -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -I"C:\Perl_516_portable\perl\lib\CORE" -s -L"C:\Perl_516_portable\perl\lib\CORE" -L"C:\Perl_516_portable\c\lib" C:\Perl_516_portable\perl\lib\CORE\libperl516.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libmoldname.a C:Perl_516_portable\c\i686-w64-mingw32\lib\libkernel32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libuser32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libgdi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinspool.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libcomdlg32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libadvapi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libshell32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libole32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\liboleaut32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libnetapi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libuuid.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libws2_32.a C:Perl_516_portable\c\i686-w64-mingw32\lib\libmpr.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinmm.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libversion.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libodbc32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libodbccp32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libcomctl32.a
In file included from C:\Perl_516_portable\perl\lib\CORE/sys/socket.h:180:0,
from C:\Perl_516_portable\perl\lib\CORE/win32.h:356,
from C:\Perl_516_portable\perl\lib\CORE/win32thread.h:4,
from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834,
from K:\Scripts\Embed\Hello_3\hello.c:2:
C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" within comment [-Wcomment]
C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" within comment [-Wcomment]
In file included from C:\Perl_516_portable\perl\lib\CORE/win32thread.h:4:0,
from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834,
from K:\Scripts\Embed\Hello_3\hello.c:2:
C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" within comment [-Wcomment]
C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" within comment [-Wcomment]
K:\Scripts\Embed\Hello_3\hello.c: In function 'main':
K:\Scripts\Embed\Hello_3\hello.c:37:1: warning: control reaches end of non-void function [-Wreturn-type]
It will not work if you are in a different path than your script and c files. Remove the absolute paths K:\Scripts\Embed\Hello_3\
The "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption?
If hello.pl does not use any libs, yes.
int main(int argc, char **argv, char **env)
{
argv[1] = "-Ilib";
argv[2] = "hello.pl";
...
This will only work if argc is 2, i.e. you provided 2 args to your hello.exe.
You rather need to check argc and extend argv if < 2, and set argc to 2 if < 2.
Step into the executable with gdb and see what's going wrong. Compile with -g then.
In the long term, the established solution is to use PAR::Dist, or one of the commercial packers. Using the real compiler perlcc on Windows is a bit tricky.

Gtkbuilder error

I have installed GTK+- 2.10.14 with directFB backend for my powerpc target board, i could able to run the example application in my target board and see the gui comes up in target LCD.with that i started creating GUI using glade but while working on Glade to create my own GUI i found that glade required gtkbuildet to compile a .glade file. the gtkbuilder is available from version GTK+-2.12.0, so installed again the GTK+-2.12.0 and fallowed procedure say in this tutorial.
My program as follows:
#include<gtk/gtk.h>
int
main( int argc,char **argv )
{
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
/* Init GTK+ */
gtk_init( &argc, &argv );
/* Create new GtkBuilder object */
builder = gtk_builder_new();
/* Load UI from file. If error occurs, report it and quit application.
* * Replace "tut.glade" with your saved project. */
if( ! gtk_builder_add_from_file( builder, "graph.glade", &error ) )
{
g_warning( "%s", error->message );
g_free( error );
return( 1 );
}
/* Get main window pointer from UI */
window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
/* Connect signals */
gtk_builder_connect_signals( builder, NULL );
/* Destroy builder, since we don't need it anymore */
g_object_unref( G_OBJECT( builder ) );
/* Show window. All other widgets are automatically shown by GtkBuilder */
gtk_widget_show( window );
/* Start main loop */
gtk_main();
return( 0 );
}
Now when I compile the above program I struck up with as error as below:
powerpc-linux-gnu-gcc progressbar.c -o progressbar -pthread -I/opt/gtkdfb/usr/local/include/glib-2.0 -I/opt/gtkdfb/usr/local/lib/glib-2.0/include -I/opt/gtkdfb/usr/local/include/pango-1.0 -I/opt/gtkdfb/usr/local/include/cairo -I/opt/gtkdfb/usr/local/include -I/opt/gtkdfb/usr/local/freetype2 -I/opt/gtkdfb/usr/local/libpng12 -I/opt/gtkdfb/usr/local/includegtk-2.0 -D_REENTRANT -D_GNU_SOURCE -I/opt/gtkdfb/usr/include/directfb -L/opt/gtkdfb/usr/local/lib -ldirectfb -lfusion -ldirect -lpthread -ldl -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lxml2 -lpng12 -lgthread-2.0 -lgtk-directfb-2.0 -lffi -lz -lm `pkg-config gtk+-2.0 --cflags --libs`
/tmp/ccZ9fkFp.o: In function `main':
progressbar.c:(.text+0x3c): undefined reference to `gtk_builder_new'
progressbar.c:(.text+0x58): undefined reference to `gtk_builder_add_from_file'
progressbar.c:(.text+0xb0): undefined reference to `gtk_builder_get_object'
progressbar.c:(.text+0xd8): undefined reference to `gtk_builder_connect_signals'
collect2: ld returned 1 exit status
make: *** [helloworld] Error 1
Please help me to come out of this error.
When there was no GtkBuilder, libglade was used instead. You must use a glade version that supports both GTK+2 and libglade (the 3.8 branch fits the bill).
Do not try to use the directFB back-end on newer GTK+: it was actively maintained by a developer of the Debian installer but it has been abandoned since a long time.
My guess is that pkg-config is still pointing to the old 2.10 version. I also don't understand why you have pkg-config gtk+-2.0 --cflags --libs and also provide all the GCC command line arguments. That is supposed to be the job of pkg-config.