g++ -Iinc ?

SRCS=x.cc y.cc xmysql.cpp
CC=g++
CFLAGS=-Iinc -O2 -Wall -W
LIBS=-L/x/mysql/lib -lmysqlclient -lz

.SUFFIXES: .cc .o
OBJS=$(SRCS:.cc=.o)

$(PROG): $(OBJS)
        $(CC) $(LIBS) $(OBJS) -o $@

.cc.o:
        $(CC) $(CFLAGS) -c $<



undefined reference to `mysql_init'
undefined reference to `mysql_real_connect'
undefined reference to `mysql_insert_id'
....

what does -Iinc do, how can i compile mysql support into this program.

LVL 7
ed987Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
efnConnect With a Mentor Commented:
-Iinc tells the compiler to look for files referenced in #include directives in a directory named "inc".  This option wouldn't be involved in a linking problem.

I can't tell why you are getting the undefined reference errors.  Are there any other error messages?
0
 
yuy2002Commented:
"-linc" means link to libinc.a ,it isn't a option of g++ compiler.
Maybe the code should write like this:
CFLAGS=-O2 -Wall -W
LIBS=-L/x/mysql/lib -lmysqlclient -lz -linc
0
 
yuy2002Commented:
sorry ,mis read.
"Iinc" means the path to the including file directory named"inc".
you can create a variable to do this:
INCLUDE_PATH   =   -Iinc
CFLAGS=$( INCLUDE_PATH)  -O2 -Wall -W

So you can define many other include directories.
>>undefined reference to `mysql_init'
>>undefined reference to `mysql_real_connect'
>>undefined reference to `mysql_insert_id'

Maybe the include path you defined was error, so the complier didn't find the reference to this mysql variables.Make sure your include path is correct to point to the directory of mysql include.

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
evilrixSenior Software Engineer (Avast)Commented:
As already stated -Iinc is telling the compiler to include path 'inc' as part of its standard search criteria when including header files that have been included using the #include <> form of the include precompile directive. As it stands the path provided will be relative from where the makefile is run from, so the inc directory must be a sub-directory. If it isn't the compiler will silently ignore this but you'll then get build related errors. That said, the type of build errors I would expect you to see would be telling you it can't find header files so I suspect your include path is probably correct and as such your problem isn't actually related to this.

The error 'undefined reference' is actually a linker error that means it cannot find the definition (body) of a function that has been declared somewhere in your code. This is probably because you either need to link to the object code or library that provides support for that function of your order of inclusion is wrong. With gcc it is necessary to list dependers before dependees, so if A depends on B you must link to A first so the linker knows what to pull out of B. SO, if you are linking to a library that provides mysql support you need to link to that last. This is counter intuitive and catches out a lot of people! Make sure you are linking to the libraries you need in the correct order.

This link should help you resolve this...

http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html

Good luck.

-Rx.
0
 
Infinity08Commented:
Does the /x/mysql/lib directory contain the libmysqlclient.a library ? Usually it's in /usr/lib/mysql
0
 
evilrixSenior Software Engineer (Avast)Commented:
This web page tells you the correct way to link to the mysql libraries -- including discovering where they live...

http://dev.mysql.com/doc/refman/5.0/en/link-errors.html
0
 
evilrixSenior Software Engineer (Avast)Commented:
"When you are linking an application program to use the MySQL client library, you might get undefined reference errors for symbols that start with mysql_, such as those shown here:
 
/tmp/ccFKsdPa.o: In function `main':
/tmp/ccFKsdPa.o(.text+0xb): undefined reference to `mysql_init'
/tmp/ccFKsdPa.o(.text+0x31): undefined reference to `mysql_real_connect'
/tmp/ccFKsdPa.o(.text+0x57): undefined reference to `mysql_real_connect'
/tmp/ccFKsdPa.o(.text+0x69): undefined reference to `mysql_error'
/tmp/ccFKsdPa.o(.text+0x9a): undefined reference to `mysql_close'

You should be able to solve this problem by adding -Ldir_path -lmysqlclient at the end of your link command, where dir_path represents the pathname of the directory where the client library is located. To determine the correct directory, try this command:

shell> mysql_config --libs

The output from mysql_config might indicate other libraries that should be specified on the link command as well."
0
 
evilrixSenior Software Engineer (Avast)Commented:
Um, the accepted answer didn't fully answer your Q -- other experts assisted in doing that. This should have been closed with a points split!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.