Solved

g++ -Iinc ?

Posted on 2007-11-15
8
513 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 500 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

630 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