MySQL++

Undefined symbols for architecture x86_64 on MacOS X
Login

Undefined symbols for architecture x86_64 on MacOS X

Undefined symbols for architecture x86_64 on MacOS X

(1) By Norris (nmerritt) on 2021-04-02 21:36:07 [link] [source]

Hi, I used homebrew to install mysql++ on my Mac and I am able to compile fine with gcc but the linker is complaining that it cannot find 64 bit libraries to link with. Any suggestions? Do I really have to build everything from source to get suitable libraries? Thanks in advance

(2) By Warren Young (tangent) on 2021-04-05 16:53:37 in reply to 1 [source]

Any suggestions?

  1. Include the actual error messages instead of making me guess at them.

  2. Follow the instructions emitted by brew install mysql++:

mysql-client is keg-only, which means it was not symlinked into /usr/local,
because it conflicts with mysql (which contains client libraries).

If you need to have mysql-client first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> /Users/tangent/.bash_profile

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

For pkg-config to find mysql-client you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql-client/lib/pkgconfig"

I offer this second option based on a guess: you've got multiple installs of the MySQL C client libraries, so your build options are finding one of the non-Brew ones. If so, following the advice from #1 would've reduced this guess to a near certainty.

Help people help you!

Do I really have to build everything from source to get suitable libraries?

Probably not, but it can't hurt, either.

(3) By Norris (nmerritt) on 2021-04-05 21:22:58 in reply to 2 [link] [source]

Thank you for responding. I did try setting the LDFLAGS. Here is the complete error message:

Building target: MySqlPPtest Invoking: MacOS X C++ Linker g++ -L/usr/local/opt/mysql-client/lib -o "MySqlPPtest" ./src/test.o
Undefined symbols for architecture x86_64: "mysqlpp::Connection::query(char const*)", referenced from: interactive() in test.o

(followed many more similar messages for other mysqlpp symbols)

(4) By Warren Young (tangent) on 2021-04-06 03:35:00 in reply to 3 [link] [source]

There's no -lmysqlpp in that command. How did you expect the compiler to find MySQL++ if you don't point it at it?

You also haven't pointed it at the MySQL C API library, -lmysqlclient, upon with MySQL++ is based.

Other libraries may also be needed, depending on how the Homebrew folks built both libraries. (e.g. -lpthread, -lssl, -lz...)

Ultimately, this comes down to understanding your tools, not understanding MySQL++. Study the provided Makefiles for examples.