List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:July 26 2008 12:53am
Subject:Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"
View as plain text  
On Jul 25, 2008, at 6:08 AM, Alex wrote:

> Like this?:
>
>> g++ \
>> -I./lib/MySQLPP -I./lib/TCLAP -I./lib/Miscellaneous \
>> ./src/Main.cpp -o ./bin/AWIWorldServer;
>> -lmysqlpp -lpthread -lnsl -lresolv \
>> `mysql_config --cflags` `mysql_config --libs`

No, like this:

g++ -I./lib/MySQLPP -I./lib/TCLAP -I./lib/Miscellaneous `mysql_config  
--cflags` src/Main.cpp -o bin/AWIWorldServer -lmysqlpp  `mysql_config  
--libs_r` -lpthread -lnsl -lresolv

It might help for you to realize that there are really two separate  
commands combined here: build C++ source code to an object file (.o),  
then link that object to several libraries, creating an executable  
file.  The .o file is then deleted when you give the command like  
this; it's treated like one of the several other temporary files a  
compiler makes when building a program.

Let's break this up so you can see things more clearly:

g++ -I./lib/MySQLPP -I./lib/TCLAP -I./lib/Miscellaneous `mysql_config  
--cflags` -c -o obj/AWIWorldServer.o src/Main.cpp

g++ obj/AWIWorldServer.o -o bin/AWIWorldServer -lmysqlpp   
`mysql_config --libs_r` -lpthread -lnsl -lresolv

For building .o files, flags tend to go to the start of the line, in  
the Unix way.  There is nothing special about the order of the flags  
in this command.  Notice that I moved the -o before the src/Main.cpp  
bit.  This is just good style, not a requirement.  The only thing  
added is -c, to make it compile to an .o file instead of trying to  
make an executable directly.  (I'm assuming the existence of an obj  
directory, too.)

The next command uses the compiler in "link mode", so order does  
matter.  This is because it passes these arguments on to a separate  
program (ld, usually) which has its own rules.  You don't really have  
to use g++ here, you can call ld (or whatever it's called on your  
system) directly.  People usually don't do that because there's a lot  
of variation among Unixy linkers, knowledge the compiler already has  
to have, so it's best to just let the compiler figure out how to call  
the linker.
Thread
"undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex24 Jul
  • Re: "undefined reference to `mysqlpp::Connection::connect(char const*,char const*, char const*, char const*, unsigned int)'"Warren Young24 Jul
    • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex25 Jul
      • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young26 Jul
Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young26 Jul
Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex27 Jul
  • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young27 Jul
Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex27 Jul
  • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young28 Jul
    • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex28 Jul
      • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young28 Jul
        • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex28 Jul
          • Re: "undefined reference to `mysqlpp::Connection::connect(char const*,char const*, char const*, char const*, unsigned int)'"Warren Young28 Jul
            • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex29 Jul
              • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young29 Jul
                • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex29 Jul
                  • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Warren Young29 Jul
                    • Re: "undefined reference to `mysqlpp::Connection::connect(char const*, char const*, char const*, char const*, unsigned int)'"Alex29 Jul