Solved

g++ -Iinc ?

Posted on 2007-11-15
8
502 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
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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now