How to setup Netbeans for MySQL programming in C - mysql

I am trying to develop an application in C in a target Linux system which requires Mysql Conectivity but i dont know where to include in NETBEANS the required directives for the libmysqlclient-dev library.
I have the following:
A laptop with NETBEANS IDE 8.0.2 and remote build host setup.
A remote Ubuntu linux target which is the remote build host for netbeans.
apt-get install libmysqlclient-dev in the Ubuntu Target
mysql_config --libs gives:
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
mysql_config --libs gives:
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
According to the Mysql C Api Building I have to include the following:
gcc -c `mysql_config --cflags` progname.c
gcc -o progname progname.o `mysql_config --libs`
Although I am able to build my program manually in the target system, I am not sure where to add the above information in Netbeans.
P.S.1 at the momment my Netbeans build command looks like this:
gcc -o dist/Debug/GNU-Linux-x86/arguments_1 build/Debug/GNU-Linux-x86/src/args.o
P.S.2 Please be gentle. I am a newbie with Netbeans, Remote builds, C and Linux development.

Ok I have managed to get it working.
First I needed to include the Mysql Library paths to the Netbeans makefile as per this post:
gcc wont compile and run MySQL C libraries
# These are the flags that gcc requires in order to link correctly against our installed
# client packages
MYSQL_LIBS := $(shell mysql_config --cflags --libs)
Then right click on my project node , select Properties->Build->Linker->Compilation Line->Additional Options and add $(MYSQL_LIBS) to the Additional options parameter.
My problem was that I was adding it into the C compiler Additional options parameter.
But this post helped to clarify the order:
Why does the order in which libraries are linked sometimes cause errors in GCC?
So now my Netbeans gcc command looks like:
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/src/args.o.d" -o build/Debug/GNU-Linux-x86/src/args.o src/args.c
gcc -o dist/Debug/GNU-Linux-x86/arguments_1 build/Debug/GNU-Linux-x86/src/args.o -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
Thank you Lumi, Thanassis

Related

install_driver(mysql) failed: Can't locate DBD/mysql.pm in #INC ... Trouble connecting to mysql database from perl script

I am trying to use MAMP to develop locally but my perl scripts are failing to connect to my mysql database. When I review the apache log I see "install_driver(mysql) failed: Can't locate DBD/mysql.pm in #INC".
When I run > which perl I get the location of my perl installation and have added that to the perl path in my MAMP's config file.
I have also tried to install DMD::MySql using
cpan[1]> install DBD::mysql
But it fails in the end. I have included the log for the cpan installation process below. I'm hoping that someone has an idea for me.
I am pretty new with this stuff and have been trying to piece my way through for a little while now.
Any help that someone might have would be much appreciated
Thanks
****cpan log****
Checking if your kit is complete...
Looks good
Using DBI 1.636 (for perl 5.016000 on darwin-2level) installed in /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI/
Writing Makefile for DBD::mysql
Wide character in print at /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/MakeMaker.pm line 1028.
Wide character in print at /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/MakeMaker.pm line 1028.
Writing MYMETA.yml and MYMETA.json
cp lib/DBD/mysql.pm blib/lib/DBD/mysql.pm
cp lib/DBD/mysql/GetInfo.pm blib/lib/DBD/mysql/GetInfo.pm
cp lib/DBD/mysql/INSTALL.pod blib/lib/DBD/mysql/INSTALL.pod
cp lib/Bundle/DBD/mysql.pm blib/lib/Bundle/DBD/mysql.pm
cc -c -I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI -I/usr/local/Cellar/mysql/5.7.14/include/mysql -fno-omit-frame-pointer -DDBD_MYSQL_WITH_SSL -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3 -DVERSION=\"4.040\" -DXS_VERSION=\"4.040\" "-I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level/CORE" dbdimp.c
/Users/archie/perl5/perlbrew/perls/perl-5.16.0/bin/perl -p -e "s/~DRIVER~/mysql/g" /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI/Driver.xst > mysql.xsi
/Users/archie/perl5/perlbrew/perls/perl-5.16.0/bin/perl /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/xsubpp -typemap /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/typemap mysql.xs > mysql.xsc && mv mysql.xsc mysql.c
Warning: duplicate function definition 'do' detected in mysql.xs, line 249
Warning: duplicate function definition 'rows' detected in mysql.xs, line 673
cc -c -I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI -I/usr/local/Cellar/mysql/5.7.14/include/mysql -fno-omit-frame-pointer -DDBD_MYSQL_WITH_SSL -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3 -DVERSION=\"4.040\" -DXS_VERSION=\"4.040\" "-I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level/CORE" mysql.c
Running Mkbootstrap for DBD::mysql ()
chmod 644 mysql.bs
rm -f blib/arch/auto/DBD/mysql/mysql.bundle
LD_RUN_PATH="/usr/local/Cellar/mysql/5.7.14/lib:/usr/lib" env MACOSX_DEPLOYMENT_TARGET=10.3 cc -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.bundle \
-L/usr/local/Cellar/mysql/5.7.14/lib -lmysqlclient -lssl -lcrypto \
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [blib/arch/auto/DBD/mysql/mysql.bundle] Error 1
MICHIELB/DBD-mysql-4.040.tar.gz
/usr/bin/make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
MICHIELB/DBD-mysql-4.040.tar.gz : make NO
make is reporting a missing library (ssl). You have to install ssl libraries first.
Or you may try to install and use DBD::mysqlPP

MySQL UDF Lib Install

I'm trying to install and use MySql UDF Lib but I'm facing an ELF error on its install procedure.
I'm under Ubuntu 14.04LTS 64.
Tried to follow some others answers and added -m64 flag for compiler, and still having the error.
Disclaimer: I'm not linux specialist, just trying a solution for a program issue
root#server:/usr/lib/mysql/plugin# sh install.sh
Compiling the MySQL UDF
gcc -fPIC -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so
MySQL UDF compiled successfully
-e
Please provide your MySQL root password
Enter password:
ERROR 1126 (HY000) at line 29: Can't open shared library 'lib_mysqludf_sys.so' (errno: 11 /usr/lib/mysql/plugin/lib_mysqludf_sys.so: wrong ELF class: ELFCLASS32)
ERROR: unable to install the UDF
root#server:/usr/lib/mysql/plugin#
My mysql file command:
root#server:/usr/bin# file mysql
mysql: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=23996cc38af44cd87dbcde82f46c47f9047769b0, stripped
And my lib file command:
root#server:/usr/lib# file lib_mysqludf_sys.so
lib_mysqludf_sys.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=8bcbe183af9bd452325f14c89810a34c5bfbbedd, not stripped
And my mysqld file command:
root#server:/run/mysqld# file /usr/sbin/mysqld
/usr/sbin/mysqld: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=eaac3628f59f9bfefceacef50d86d8cb834c0a7a, stripped
A bit late response, but better than never I hope :)
You are installing the plugin to /usr/lib
gcc -fPIC -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so
But your MySQL server is only looking for plugins installed on /usr/lib/mysql/plugin.
So, changing the above gcc command to
gcc -fPIC -Wall -m64 -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/mysql/plugin/lib_mysqludf_sys.so
Should fix the Can't open shared library 'lib_mysqludf_sys.so' error.
Hope this helps.

mysql udf error - can't install in ubuntu 12.04 64 bit

I have trouble installing the mysql udf (https://github.com/mysqludf/lib_mysqludf_sys). Here's what I'm getting:
Compiling the MySQL UDF
gcc -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so
/usr/bin/ld: /tmp/ccw6HRtN.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccw6HRtN.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [install] Error 1
ERROR: You need libmysqlclient development software installed
to be able to compile this UDF, on Debian/Ubuntu just run:
apt-get install libmysqlclient15-dev
Any ideas? TIA
UPDATED:
I have already the libmysqlclient15-dev installed.
Try to recompile with -fPIC flag. It obviously hints at it:
/usr/bin/ld: /tmp/ccw6HRtN.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
I know this is an old question, however I've just had this issue using Ubuntu 16.
I solved changing the Makefile in the following way, as explained in a GitHub issue:
LIBDIR=/usr/lib/mysql/plugin
install:
gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so

Installing bugzilla with mysql

I'm trying to install Bugzilla as part of setting up Testopia. I'm using 3.6.3 because our company site uses that and there are no plans to upgrade in the foreseeable future. I've install mysql but when I run the /usr/bin/perl install-module.pl DBD::mysql script it fails. The error message though isn't very descriptive. I've included it below:
Running Mkbootstrap for DBD::mysql ()
chmod 644 mysql.bs
rm -f blib/arch/auto/DBD/mysql/mysql.so
LD_RUN_PATH="/home/y/lib/mysql:/lib64" /usr/bin/perl myld gcc -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.so \
-L/home/y/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto \
/usr/bin/ld: skipping incompatible /home/y/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status
make: * [blib/arch/auto/DBD/mysql/mysql.so] Error 1
CAPTTOFU/DBD-mysql-4.021.tar.gz
/usr/bin/make -- NOT OK
Skipping test because of notest pragma
Running make install
Make had returned bad status, install seems impossible
I don't know why libmysqlclient.so is incompatible. Is the installed version of mysql too old or is it too recent for this version of Bugzilla? The error message does not specify. Can anyone help?
this looks like this which suggest you update your operating system.
hope this could help

makefile error ----> make: *** No rule to make target `mysql.h'

This might sound like a dumb question. But here goes..... I am using a C program called db_access.c which interacts with MySQL (in Ubuntu 10.10 with MySQL Server version: 5.1.49-1ubuntu8.1 (Ubuntu)). Inside the program, I have: include "mysql.h"
When I do the following, everything works out right:
gcc -I/usr/include/mysql db_access.c -lmysqlclient -o db_access
./db_access
Problem arises when I try to integrate it into an existing (and working makefile). The contents of the makefile:
all: MappingServer
#Macro definitions
CC = gcc
CFLAGS = -lm
INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient
MappingServer.o: MappingServer.c map_registration.h
$(CC) $(CFLAGS) -c MappingServer.c
route_aggregation.o: route_aggregation.c map_registration.h
$(CC) $(CFLAGS) -c route_aggregation.c
db_access.o: db_access.c map_registration.h mysql.h
$(CC) $(CFLAGS) $(INCLUDES) -c db_access.c
MappingServer: MappingServer.o route_aggregation.o db_access.o
$(CC) $(LIBS) -o MappingServer MappingServer.o route_aggregation.o db_access.o
clean:
-rm MappingServer.o route_aggregation.o db_access.o
I have two other C programs, MappingServer.c and route_aggregation.c. These 3 files need to be compiled together. By the way, I also did:
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
and
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
So I think the paths are OK. When I do: make all
I get:
root#ahuq-kitchen:/home/ahuq/MappingServer# make all
gcc -lm -c MappingServer.c
gcc -lm -c route_aggregation.c
route_aggregation.c: In function ‘vtysh_input’:
route_aggregation.c:602: warning: function returns address of local variable
make: *** No rule to make target `mysql.h', needed by `db_access.o'. Stop.
Why is this happening?
the line
db_access.o: db_access.c map_registration.h mysql.h
tells make that db_access.o depends on db_access.c, map_registration.h and mysql.h. make complains because mysql.h cannot be found in the current directory (it's in /usr/include/mysql).
see the question Makefile updated library dependency for how to specify libraries as dependencies in make
You put "mysql.h" as a dependency, but it's not in the current directory, so Make thinks it needs to build it, but doesn't know how.
try to remove all the lines like:
MappingServer.o: MappingServer.c map_registration.h
if the map_registration.h is included in the c file, make is smart enough to find it. The only thing to be noticed may be to set the search file path using: -I.