[CMake] works when I build using XCode, but not with CMake makefile

Cotton Candy cottoncandycoder at gmail.com
Wed Sep 7 07:18:25 EDT 2016


Hi Peter,
I attach my CMakeLists.txt file as well as the FindMySQL.cmake finder that
I used, in case these help.

I still get the same error when I run the executable:
dyld: Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/schurger/tmp/test_CMake2/./skedmo-solver
  Reason: image not found
Trace/BPT trap: 5

This library (libmysqlclient.18.dylib) is in /usr/lib on my machine.

Thanks for all your help.
Aaron

On Wed, Sep 7, 2016 at 9:36 AM, Peter Steinbach <steinbach at scionics.de>
wrote:

> Hi Mr Candy (I am still getting a heck out of cottoncandycoder, sorry :D )
>
> 1) the way you do it, is not really the way cmake should be used AFAIK.
> > In my CMakeLists.txt file I included:
> > set( CMAKE_CXX_FLAGS  "-L/Applications/MAMP/Library/lib -lmysqlclient
> > -lpthread -lz" )
> > set( CMAKE_EXE_LINKER_FLAGS  "-lmysqlclient -lpthread -lm -lz" )
>
> change this to:
> #I assume you have something like this somewhere
> add_executable(my_exe_name SOURCES my_exe_name.???)
> #here comes the "magic"
> link_directories(/Applications/MAMP/Library/lib)
> target_link_libraries(mysqlclient pthread m z)
>
> In theory, if all those dependencies are available at cmake-invocation,
> this should emit compiler calls that produce your binary and link
> mysqlclient into it (by default with using RPATH, see the docs on this:
> https://cmake.org/cmake/help/v3.0/prop_tgt/MACOSX_RPATH.
> html#prop_tgt:MACOSX_RPATH
> ). Depending on whether you wanna distribute your binary and cannot be
> sure if (at build time) pthreads etc are available, there are cmake find
> modules for pthreads and libz (FindThreads, FindZLIB) which you can use.
> libm should come with the libc of the system AFAIK.
>
> I also just checked but up to cmake 3.5, there is no MYSQL Find module.
> Which is kinda sad as there is a FindPostgreSQL module. :( If there would
> be, you could use it in a (hopefully) platform independent way and not
> bother with finding the right paths to libmysqlclient.
>
> 2) The compiler flags you posted do not explain, why Xcode apparently sets
> the rpath inside the binary and your cmake script doesn't (haven't seen the
> full CMakeLists.txt of your project yet).
>
> I hope the above gets you going.
>
> @cmake developers: it would be nice to have more obvious pointers to cmake
> example projects like an example SDK or so. If there is, please let me
> know. I only found this:
> http://www.vtk.org/Wiki/CMake/Examples#Finding_Packages
> but that's tied to vtk.
>
> Best,
> peter
>
> On 09/06/2016 08:12 PM, Cotton Candy wrote:
> > Peter,
> > In XCode I have this list of "settings" that includes
> > "Other Linker Flags" that I have set to "-lmysqlclient -lpthread -lm -lz"
> > and
> > "Other C++ Flags" that I have set to "-L/Applications/MAMP/Library/lib
> > -lmysqlclient -lpthread -lz"
> >
> > Maybe these explain why things work when I build with XCode, but not with
> > CMake.
> >
> >
> > but when I run the make it always says it is ignoring these (e.g.
> "warning:
> > argument unused during compilation: '-L/Applications/MAMP/Library/
> lib'").
> >
> > Thanks again for you help.
> > Aaron
> >
> >
> >
> >
> >
> > On Tue, Sep 6, 2016 at 2:20 PM, Peter Steinbach <steinbach at scionics.de>
> > wrote:
> >
> >> Aaron,
> >>
> >> it's about the way that you compile your binary and link libmysqlclient
> >> into it. I guess (@all: please correct me if I am wrong) as I don't know
> >> how you use cmake to build your libraries/binaries, that you don't set
> the
> >> rpath of libmysqlclient inside your binary. Doing so will ensure that
> the
> >> absolute path of libmysqlclient is stored into your binary, so that the
> >> runtime environment can pick it up and use (keeping fingers crossed that
> >> the path is still valid). The alternative to doing so, is linking
> against
> >> the static version of libmysqlclient (which comes at a cost on another
> >> front as well).
> >>
> >> Best,
> >> P
> >>
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160907/8b3e555f/attachment-0001.html>
-------------- next part --------------
cmake_minimum_required(VERSION 3.5)
project(skedmo_solver_lean)

#set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_BUILD_TYPE Debug)

set(SOURCE_FILES
    cgi_input.cpp
    cgi_input.h
    main.cpp
    main.h
    solver.cpp
    solver.h
    stack.cpp
    stack.h
    supporting.cpp
    supporting.h)

set(skedmo_INCLUDE_DIRS
    /usr/local/eigen
    /usr/local/boost_1_56_0
    /usr/local/connector-c/include
    /usr/local/connector-c/lib
    /usr/local/lib
    /usr/local/connector-c)

include_directories(${skedmo_INCLUDE_DIRS})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/Users/schurger/Dropbox/Skedmo/skedmo-solver-lean/cmake/")

find_package(MySQL)

add_executable(skedmo-solver ${SOURCE_FILES})
link_directories(/Applications/MAMP/Library/lib /usr/lib)
target_link_libraries(skedmo-solver mysqlclient pthread m z)
target_link_libraries(skedmo-solver ${MYSQL_LIBRARY})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindMySQL.cmake
Type: application/octet-stream
Size: 1231 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160907/8b3e555f/attachment-0001.obj>


More information about the CMake mailing list