?
Solved

g++ -Iinc ?

Posted on 2007-11-15
8
Medium Priority
?
516 Views
Last Modified: 2011-09-20
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.

0
Comment
Question by:ed987
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:yuy2002
ID: 20295137
"-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
 
LVL 15

Accepted Solution

by:
efn earned 2000 total points
ID: 20295521
-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
 
LVL 4

Expert Comment

by:yuy2002
ID: 20295747
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:evilrix
ID: 20296760
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 20296769
Does the /x/mysql/lib directory contain the libmysqlclient.a library ? Usually it's in /usr/lib/mysql
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20296825
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
 
LVL 40

Expert Comment

by:evilrix
ID: 20296829
"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
 
LVL 40

Expert Comment

by:evilrix
ID: 20338060
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question