Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

EDIT: I solved my issue - I was editing the wrong include file. See the end of this post for the fix.

I'm migrating some applications from an old FreeBSD 4.3 server to a new FreeBSD 10 server. These are C applications that use the MySQL C API. They are very very old and use the mysql_connect function (which is deprecated in newer versions of MySQL). From what I can gather looking at the MySQL source, the MySQL client API needs to be compiled with USE_OLD_FUNCTIONS. Unfortunately I can't figure out how to do this. I'm attempting to install MySQL 5.6 with the FreeBSD ports system. I did the following, which I think should work:

cd /usr/ports/databases/mysql56-client
make fetch
make extract
make configure

I then edited work/mysql-5.6.16/include/config.h and added the following line at the very end:

#define USE_OLD_FUNCTIONS

Then I compiled and installed the client:

make
make install

mysql_config shows the following:

# mysql_config --libs
-L/usr/local/lib/mysql -lmysqlclient  -pthread -lm
# mysql_config --cflags
-I/usr/local/include/mysql -pipe -fno-strict-aliasing -g -DNDEBUG

When I attempt to compile a very simple test client, shown below, I get a linker error that says undefined reference to 'mysql_connect'. Test client code is as follows:

#define USE_OLD_FUNCTIONS
#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
  MYSQL *sock;
  sock = mysql_connect(NULL, NULL, "root", "test");
  mysql_close(sock);
}

When I attempt to compile it, I get a linker error:

# clang -o test -I/usr/local/include/mysql -pipe -fno-strict-aliasing -g -DNDEBUG test.c -L/usr/local/lib/mysql -lmysqlclient -pthread -lm
/tmp//ccTJC9Ov.o: In function `main':
/root/admin/test.c:8: undefined reference to `mysql_connect'
collect2: ld returned 1 exit status

The following test program, which uses the newer mysql_real_connect function, compiles just fine with the same compiler arguments and runs without error:

#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
  MYSQL *sock;
  sock = mysql_init(NULL);
  mysql_real_connect(sock, NULL, "root", "test", NULL, 0, NULL, 0);
  mysql_close(sock);
}

Any idea where I'm going wrong? The MySQL documentation for USE_OLD_FUNCTIONS seems to be nonexistent. I can't blame them since these functions have been deprecated for a long time, but the code still seems to be there.

Solution:

I think I figured it out. Instead of editing work/mysql-5.6.16/include/config.h, I should have edited work/mysql-5.6.16/include/my_config.h. I added the following to the latter file, recompiled MySQL, and my test program compiles and links just fine now.

#define USE_OLD_FUNCTIONS

Note that I added this to my_config.h just before the last #endif in the file. Hopefully this helps someone else in the future.

share|improve this question
1  
Could you please post that solution as an Answer below. Thank you! –  Chris S Feb 14 at 14:26
    
@ChrisS - I tried, but it won't let me post an answer to my own question until 8 hours have passed. I'll come back later and post it as an answer. –  hcsteve Feb 14 at 14:30

1 Answer 1

up vote 0 down vote accepted

I think I figured it out. Instead of editing work/mysql-5.6.16/include/config.h, I should have edited work/mysql-5.6.16/include/my_config.h. I added the following to the latter file, recompiled MySQL, and my test program compiles and links just fine now.

#define USE_OLD_FUNCTIONS

Note that I added this to my_config.h just before the last #endif in the file. Hopefully this helps someone else in the future.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.