George.Ef
George.Ef

Reputation: 165

How to setup Netbeans for MySQL programming in C

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:

  1. A laptop with NETBEANS IDE 8.0.2 and remote build host setup.
  2. A remote Ubuntu linux target which is the remote build host for netbeans.
  3. apt-get install libmysqlclient-dev in the Ubuntu Target
  4. mysql_config --libs gives:

-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl

  1. 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.

Upvotes: 2

Views: 512

Answers (1)

George.Ef
George.Ef

Reputation: 165

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

Upvotes: 2

Related Questions