Problems compiling with Makefile


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problems compiling with Makefile
# 1  
Old 02-18-2012
Problems compiling with Makefile

Hey guys!

To avoid Smilie for another 5 hours, I'm posting here to hopefully resolve this silly issue once and for all. I'd appreciate if you could simply provide the full makefile I should use, and then explain what does what. I've been studying dissected examples for hours now and none of it's helped!

Here's my current version:
Code:
INCLUDES    = -I /usr/include/mysql -I /usr/local/include/mysql++
CXXFLAGS    = -g -Wall $(INCLUDES)
OBJS        = main.o
LIBS        = -L /usr/lib/mysql -L /usr/local/lib
PROG        = test

all:        $(PROG)

$(PROG):    $(OBJS)
            $(CXX) $(INCLUDES) $(LIBS) $(OBJS) -o $(PROG)

clean:;        $(RM) -f $(PROG) core *.o

I'm trying to get a simple MySQL script for C++ working using the MySQL++ library. Obviously, it uses only main.cpp at the moment.

Include dependencies are
  • /usr/include/mysql/mysql_version.h (among other files)
  • /usr/local/include/mysql++/mysql++.h (among other files)
Library dependencies are
  • /usr/lib/mysql/libmysqlclient.so
  • /usr/local/lib/libmysqlpp.so
main.ccp has #include <mysql++.h>
mysql++.h has #include <mysql_version.h> (among other mysql files)

This current setup produces
Code:
g++ -g -Wall -I /usr/include/mysql -I /usr/local/include/mysql++   -c -o main.o main.cpp
g++ -I /usr/include/mysql -I /usr/local/include/mysql++ -L /usr/lib/mysql -L /usr/local/lib main.o -o test
main.o: In function `main':
[omitted]/MySQLTest/main.cpp:16: undefined reference to `mysqlpp::Connection::Connection(bool)'
[omitted]/MySQLTest/main.cpp:17: undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'
...

with more similar errors. However, the mysqlpp namespace is clearly defined in /usr/local/include/mysql++/mysql++.h

I figure this should be a simple fix. Thanks for your help!
# 2  
Old 02-18-2012
It looks like you've listed the search directories for libraries (-L), but not the libraries them selves. For example, if you need to link with the mpeg2 library, you'd also have -lmpeg2 on your command line.

Assuming from your post that you need libmysqlclient.so and libmysqlpp.so the first thing I'd do is to change your LIB variable to be:

Code:
LIBS = -L /usr/lib/mysql -lmysqlclient  -L /usr/local/lib -lmysqlpp

I prefer a space between the L and library name, but I have worked in some environments that require them to not be separated, so you might have to adjust that too.
This User Gave Thanks to agama For This Post:
# 3  
Old 02-18-2012
WOW. Yes, that was the problem. I did mess with specifying the library directly, but nothing told me that you only specify the middle part of the filename... how annoying. Thanks so much!

So basically out of libanything.so.999.0.2, you only provide -lanything

I'm definitely not going to mess that up again, considering how much time this has taken up.
# 4  
Old 02-18-2012
Quote:
Originally Posted by Liandri
WOW. Yes, that was the problem. I did mess with specifying the library directly, but nothing told me that you only specify the middle part of the filename... how annoying. Thanks so much!

So basically out of libanything.so.999.0.2, you only provide -lanything

I'm definitely not going to mess that up again, considering how much time this has taken up.
Glad that worked. You might want to have a read through the linker man page (man ld).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. SuSE

Problem compiling the kernel and linking problems in OpenSuse 12.3

Hi everyone I installed OpenSuse 12.3 and many development tools but when i propose build the kernel from the source (the first step make menuconfig) i saw this: HOSTLD scripts/kconfig/mconf /usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: warning: libdl.so.2,... (2 Replies)
Discussion started by: bacesado
2 Replies

2. Red Hat

problems compiling openldap

I hope this is the right place to post this and that I can get some help. I pretty much suck at troubleshooting build issues. we are running oracle red-hat linux 2.6.32-200.20.1.el5uek #1 SMP Fri Oct 7 02:29:42 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux trying to build the latest stable version of... (3 Replies)
Discussion started by: fwellers
3 Replies

3. Programming

Problems compiling code

I am trying to compile some code and getting lot of errors g++ -traditional -Wno-non-template-friend -Wno-deprecated -O3 -DNDEBUG -DREAL=float -DGetREAL=Getfloat -IbaseLib -Itommy -Iothers ./source/main/RayTrac.cc -o raytrac ./source/main/RayTrac.cc:36:20: error: gendef.h: No such file or... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

5. UNIX for Dummies Questions & Answers

Compiling DigSig fails: Compiler/Makefile output

Hey, I'm trying to install DigSig ( disec.sourceforge.net ) on my CentOS5 distro. I was following all the steps in the readme but it didn't work. So here's the output: # ./digsig.init compile make: Entering directory `/usr/src/kernels/2.6.18-194.32.1.el5-i686' CC ... (2 Replies)
Discussion started by: disaster
2 Replies

6. Programming

Problems compiling OpenStep program.

I use Ubuntu 10.4, and I installed GNUStep, Gorm (a gui builder) and ProjectCenter (the GNU alternative to Xcode) because I want to develop Objective-C apps. I opened the ProjectCenter and I created an application that displays only an empty window. I sourced the GNUstep.sh and I compiled the app. ... (0 Replies)
Discussion started by: mghis
0 Replies

7. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

8. AIX

Purify and AIX compiling problems.

Hi, i'm trying to work with a trial version of PurifyPlus 7 with fixpack 10 from Rational that needs to run over an AIX 5.3 platform, 64-bit. I had success on compiling and running the hello_world programs and even a hash test program i found over the net, but purify can achieve the same with the... (0 Replies)
Discussion started by: chrispav
0 Replies

9. Programming

my problems with MAKEFILE command

Hi everyone. I'm a newbies in using c++ in UNIX. And since then I only do maintenance coding not development. so far i understand c++ coding and OOP concepts. currently i'm working onsomething for maintenance purpose.here's the situation : below are my files : source files: advDisc.cpp ... (2 Replies)
Discussion started by: aliasunway
2 Replies
Login or Register to Ask a Question