| Bug #63298 | HP-UX build fails due to a wrong setting of myodbc3u COMPILE_FLAGS | ||
|---|---|---|---|
| Submitted: | 17 Nov 2011 2:16 | Modified: | 10 May 2013 6:23 |
| Reporter: | Alex Goncharov | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / ODBC | Severity: | S3 (Non-critical) |
| Version: | 5.1.9 | OS: | HP/UX |
| Assigned to: | Bogdan Degtyariov | CPU Architecture: | Any |
| Tags: | build, cmake, CMakeLists.txt | ||
[17 Nov 2011 10:00]
Bogdan Degtyariov
Alex, thanks for reporting the bug and for the suggestion how to fix it.
[17 Nov 2011 18:30]
Lawrenty Novitsky
if no one objects i will push following patch
=== modified file 'util/CMakeLists.txt'
--- util/CMakeLists.txt 2011-09-28 09:21:45 +0000
+++ util/CMakeLists.txt 2011-11-17 18:28:19 +0000
@@ -38,7 +38,9 @@
TARGET_LINK_LIBRARIES(myodbc3u ${ODBCINSTLIB})
IF(NOT WIN32)
- SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "-fPIC")
+ IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "HP-UX")
+ SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "-fPIC")
+ ENDIF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "HP-UX")
INCLUDE_DIRECTORIES(${DL_INCLUDES})
removing -fPIC only on hp-ux in this way
[17 Nov 2011 19:11]
Alex Goncharov
You patch is plain wrong:
a. You now skip HP-UX completely and don't pass the requisite +Z flag for generating PIC code.
b. Without an extreme need, you should not pollute a module's CMakeLists.txt with platform conditions.
Here there is no such need: CMake Modules take care of it for you, and
CMAKE_SHARED_LIBRARY_C_FLAGS is defined there correctly for all covered platforms.
If you rely on CMake, you should let it determine what options to use for a given type of a build.
Take a look:
--------
cd cmake-2.8/Modules/Platform && grep -E 'MAKE_SHARED_LIBRARY_.*_FLAGS.*[zZ]' HP*
HP-UX-HP-CXX.cmake:set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "+Z -Wl,-E,+nodefaultrpath -b -L/usr/lib")
HP-UX-HP.cmake: set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "+Z")
---------
I suggest that you use the patch as I submitted it, with
---
- SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "-fPIC")
+ SET_TARGET_\
PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
----
(The bug reporting system breaks lines).
(I did test my fix on (most) Unixes, and can test more if you want.)
Thanks,
-- Alex
[17 Nov 2011 23:20]
Vladislav Vaintroub
Alex is correct.
${CMAKE_SHARED_LIBRARY_C_FLAGS} is what server is using to compile static libraries that might later be linked into shared.
-fPIC works in many cases but not all of them, and for HPUX/HP compiler the correct flag is indeed +Z. So replacing -fPIC with ${CMAKE_SHARED_LIBRARY_C_FLAGS} is the simplest fix for PIC-sensitive platforms.
[18 Nov 2011 12:19]
Lawrenty Novitsky
i agree. i must admit i misread your patch because of line break, thus an erroneous patch. as for b. it kinda feels safer to limit change only to target platform. especially given that if i am not mistaken mysql support on hp-ux is being eol'ed.
but now i see that CMAKE_SHARED_LIBRARY_C_FLAGS should do the job.
so the patch has to look just like you suggested
=== modified file 'util/CMakeLists.txt'
--- util/CMakeLists.txt 2011-09-28 09:21:45 +0000
+++ util/CMakeLists.txt 2011-11-18 12:17:51 +0000
@@ -38,7 +38,7 @@
TARGET_LINK_LIBRARIES(myodbc3u ${ODBCINSTLIB})
IF(NOT WIN32)
- SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "-fPIC")
+ SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
INCLUDE_DIRECTORIES(${DL_INCLUDES})
[18 Nov 2011 13:20]
Alex Goncharov
Great, thank you! On line-breaking: I am an occasional MySQL bug reporter, and may not know the secrets of better report formatting, but I have observed that entering text as I do now, via a browser pointing to http://bugs.mysql.com/bug.php?id=63298&edit=3, breaks lines unexpectedly in what gets posted. Maybe I'll learn to do it better as I see more results of my entries. In any case, sorry for for the confusion resulting from the line breaking in the original patch: I didn't know what the result was going to be when I pasted the text from an XTerm. (Let's see what gets posted now). Thanks again! -- Alex
[10 May 2013 6:23]
Bogdan Degtyariov
This issue has been fixed ages ago in the revision 1020 of Connector/ODBC.

Description: -fPIC is a wrong flag for /opt/ansic/bin/cc, using which results in compilation warnings, non-PIC objects cannot be linked into a shared library. How to repeat: Build on HP-UX (I was doing it on hppa2.0w-hp-hpux11.11) with CMake -DBUILD_SHARED_LIBS=ON Suggested fix: This fixes it (a platform-independent setting):' --- a/mysql-connector-odbc/mysql-connector-odbc-5.1.9/mysql-connector-odbc-5.1.9/util/CMakeLists.txt +++ b/mysql-connector-odbc/mysql-connector-odbc-5.1.9/mysql-connector-odbc-5.1.9/util/CMakeLists.txt @@ -38,7 +38,7 @@ ADD_LIBRARY(myodbc3u STATIC ${myodbc3u_SRCS}) TARGET_LINK_LIBRARIES(myodbc3u ${ODBCINSTLIB}) IF(NOT WIN32) - SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "-fPIC") + SET_TARGET_PROPERTIES(myodbc3u PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") INCLUDE_DIRECTORIES(${DL_INCLUDES})