Bug #63302 ODBC fails to link shared module
Submitted: 17 Nov 2011 11:59 Modified: 10 Jun 2013 8:57
Reporter: filippo manicone Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.1.9 OS:MacOS (Lion)
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[17 Nov 2011 11:59] filippo manicone
Description:
I cannot build ODBC on Mac OS X Lion, I already installed X-Code Tools 4.1. I'm on x86_64.

Full log is attached, the error is:
Linking C shared module ../lib/libmyodbc5.so
Undefined symbols for architecture x86_64:
  "_init_dynamic_string", referenced from:
      _mysql_procedure_columns in catalog_no_i_s.c.o
      _my_SQLSetPos in cursor.c.o
      _do_my_pos_cursor in execute.c.o
  "_dynstr_free", referenced from:
      _mysql_procedure_columns in catalog_no_i_s.c.o
      _my_SQLSetPos in cursor.c.o
      _do_my_pos_cursor in execute.c.o
  "_dynstr_append_mem", referenced from:
      _mysql_procedure_columns in catalog_no_i_s.c.o
      _insert_field in cursor.c.o
      _insert_pk_fields in cursor.c.o
      _append_all_fields in cursor.c.o
      _build_where_clause in cursor.c.o
      _build_set_clause in cursor.c.o
      _batch_insert in cursor.c.o
      ...
  "_dynstr_append_os_quoted", referenced from:
      _mysql_procedure_columns in catalog_no_i_s.c.o
  "_dynstr_append", referenced from:
      _build_where_clause in cursor.c.o
     (maybe you meant: _dynstr_append_quoted_name)
  "_strfill", referenced from:
      _str_to_ts in utility.c.o
  "_dynstr_realloc", referenced from:
      _dynstr_append_quoted_name in utility.c.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [lib/libmyodbc5.so] Error 1
make[1]: *** [driver/CMakeFiles/myodbc5.dir/all] Error 2
make: *** [all] Error 2

How to repeat:
$ cmake -G "Unix Makefiles"
$ make
[17 Nov 2011 12:00] filippo manicone
Full log

Attachment: log.txt (text/plain), 7.92 KiB.

[18 Nov 2011 10:03] Bogdan Degtyariov
Filippo, after generating files you have to run configure script and provide all needed parameters. For instance:

./configure --prefix=/usr/local \
         --with-iodbc=/usr/local \
         --with-mysql-path=/usr/local/mysql
[23 Nov 2011 4:51] Bogdan Degtyariov
Filippo,

Sorry, the procedure of building Connector/ODBC has recently changed and you do not need to execute the configure script anymore. The documentation does not reflect all needed changes and cmake files are not targeted to any other platform than Windows for the version 5.1.9. Hopefully this will change in the upcoming releases.
[9 Dec 2011 18:46] Lawrenty Novitsky
cmake files are supposed to work on all supported platforms now.
what version of mysql libraries do you have? maybe it makes sense to update them?

also it is strange that linker tries to link dynamic library, c/odbc is supposed to be linked against a static library(mysqlclient_r). so that may be an evidence that something is wrong in cmake files. i can't see that at the moment though. if dynmic library is the reason of the problem then possible workaround will be to force using of mysqlclient_r somehow.
[24 Dec 2011 16:51] Steven Palm
Same error here, I am using the 5.5.18 libraries and I even made a universal set via lipo so that architecture should not be a problem. If I set the Cmake flags for both architectures I get the same undefined symbols errors for both architectures.

The final gcc/link command is below, but it still seems to not find the symbols in libmysqlclient_r even though a nm command shows that they are in there....

Linking C shared module ../lib/libmyodbc5.so
cd /usr/local/src/mysql-connector-odbc-5.1.9/driver && "/Applications/CMake 2.8-2.app/Contents/bin/cmake" -E cmake_link_script CMakeFiles/myodbc5.dir/link.txt --verbose=1
/usr/bin/gcc    -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -bundle -headerpad_max_install_names  -o ../lib/libmyodbc5.so CMakeFiles/myodbc5.dir/ansi.c.o CMakeFiles/myodbc5.dir/catalog.c.o CMakeFiles/myodbc5.dir/catalog_no_i_s.c.o CMakeFiles/myodbc5.dir/connect.c.o CMakeFiles/myodbc5.dir/cursor.c.o CMakeFiles/myodbc5.dir/desc.c.o CMakeFiles/myodbc5.dir/dll.c.o CMakeFiles/myodbc5.dir/error.c.o CMakeFiles/myodbc5.dir/execute.c.o CMakeFiles/myodbc5.dir/handle.c.o CMakeFiles/myodbc5.dir/info.c.o CMakeFiles/myodbc5.dir/driver.c.o CMakeFiles/myodbc5.dir/options.c.o CMakeFiles/myodbc5.dir/prepare.c.o CMakeFiles/myodbc5.dir/results.c.o CMakeFiles/myodbc5.dir/transact.c.o CMakeFiles/myodbc5.dir/unicode.c.o CMakeFiles/myodbc5.dir/utility.c.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -lm ../lib/libmyodbc3u.a -liodbcinst
[24 May 2012 23:51] Ryan McCuaig
For what it's worth, I found the same issue on OS X 10.7.4. I fixed it by letting cmake generate the makefiles and then adding "/usr/local/lib/libmysqlclient_r.a" as the last thing in driver/CMakeFiles/myodbc5.dir/link.txt

I'm working to get this included in homebrew (Mac package manager), see https://github.com/mxcl/homebrew/pull/12414 ... this shows the little hack described above.
[10 May 2013 8:57] Bogdan Degtyariov
MyODBC Driver has to be linked using the static library (libmysqlclient_r.a). However, the linker always prefers using shared library over the static one when the command line has the -l option (-lmysqlclient_r).
So, you either have to remove libmysqlclient(_r).so or explicitly specify the full path to libmysqlclient_r.a.

This problem is being actively worked on. When it is solved the linker will always pick the correct static lib.
[11 Jun 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".