-1

I'm building PHP7 on an OpenWRT machine (an ARM router). I wanted to include MySQL, so I had to build that as well. OpenWRT is 99.5% ordinary linux, but there are some weird building / shared library things that probably don't get exercised often, so I've run into some difficulties.

MySQL builds OK (after some screwing around) and I have a libmysqlclient.so that works. However, the configure process for PHP7 fails when trying to link the MySQL test program, because libmysqlclient.so must be linked with the C++ standard libraries, not the C standard libs. (MySQL is apparently at least partially C++, and it uses std::...stuff....) Configure tries to compile the test program with gcc, which doesn't include the C++ libraries in the link, so the test fails.

I bodged over this by making a simple C/C++ switching script: if the command line includes -lmysqlclient then I exec g++ $* else exec gcc $*. Then I told configure to use my script as the C compiler.

It occurs to me that there must be a better way to handle this, though. It seems like libmysqlclient.so should have some way to tell the linker that it also needs libstdc++.so, so that even if gcc is used to link, all the necessary libraries would get pulled in.

Is there some way to mark dependencies in libmysqlclient.so? Or to make configure smarter about running test programs?

Dave M.
  • 1,496
  • 1
  • 12
  • 30
  • If libmysqlclient truly uses C++ code and requires linking with the C++ library, and PHP7's configure script attempts a test link, then the configure script is broken, and doesn't work with this version of mysql, and that's the end of the story. This is not uncommon situation, and Linux distribution packagers often have to deal with random glitches like that. Maybe this version of PHP is not compatible with this version of mysql. If the only problem is this configure script test, then the usual solution is to patch the configure script itself. – Sam Varshavchik Jan 06 '19 at 17:32
  • 1
    You sure that `libmysqlclient.so` links in C++? If you use mariadb, it's fully written in C [github](https://github.com/MariaDB/mariadb-connector-c). – KamilCuk Jan 06 '19 at 17:37
  • All I know is, trying to use GCC to link a C test program with `libmysqlclient.so` (compiled from MySQL-8) was failing with several `std::...` symbols missing. When I used g++ to link, it worked OK. – Dave M. Jan 06 '19 at 21:18
  • I think @SamVarshavchik is correct: it's a problem with PHP7's configure script, possibly not being updated to work with MySQL-8. I rarely do anything besides `./configure` ... `make` ... `make install`, so I haven't encountered this before. – Dave M. Jan 06 '19 at 21:19

1 Answers1

5

You should virtually never try to link with the C++ standard library manually. Use g++ for linking C++ programs. gcc knows the minute details of what library to use and where it lives, so you don't have to.

Now the question is, when to use g++, and when not to. One possible answer to that question is "always use g++". There is no harm in it. g++ can link C programs just fine. There is no overhead in the produced program. There might be some performance loss in the link process itself, but it probably won't be noticeable for any but the most humongous of programs.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243