<div dir="ltr"><div><div><div><div><div>Hi Peter,<br></div>I attach my CMakeLists.txt file as well as the FindMySQL.cmake finder that I used, in case these help.<br><br></div>I still get the same error when I run the executable:<br>dyld: Library not loaded: libmysqlclient.18.dylib<br>  Referenced from: /Users/schurger/tmp/test_CMake2/./skedmo-solver<br>  Reason: image not found<br>Trace/BPT trap: 5<br><br></div>This library (libmysqlclient.18.dylib) is in /usr/lib on my machine.<br><br></div>Thanks for all your help.<br></div>Aaron<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 7, 2016 at 9:36 AM, Peter Steinbach <span dir="ltr"><<a href="mailto:steinbach@scionics.de" target="_blank">steinbach@scionics.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mr Candy (I am still getting a heck out of cottoncandycoder, sorry :D )<br>
<br>
1) the way you do it, is not really the way cmake should be used AFAIK.<br>
<span class="">> In my CMakeLists.txt file I included:<br>
> set( CMAKE_CXX_FLAGS  "-L/Applications/MAMP/Library/<wbr>lib -lmysqlclient<br>
> -lpthread -lz" )<br>
> set( CMAKE_EXE_LINKER_FLAGS  "-lmysqlclient -lpthread -lm -lz" )<br>
<br>
</span>change this to:<br>
#I assume you have something like this somewhere<br>
add_executable(my_exe_name SOURCES my_exe_name.???)<br>
#here comes the "magic"<br>
link_directories(/<wbr>Applications/MAMP/Library/lib)<br>
target_link_libraries(<wbr>mysqlclient pthread m z)<br>
<br>
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:<br>
<a href="https://cmake.org/cmake/help/v3.0/prop_tgt/MACOSX_RPATH.html#prop_tgt:MACOSX_RPATH" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/<wbr>v3.0/prop_tgt/MACOSX_RPATH.<wbr>html#prop_tgt:MACOSX_RPATH</a><br>
). 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.<br>
<br>
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.<br>
<br>
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).<br>
<br>
I hope the above gets you going.<br>
<br>
@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:<br>
<a href="http://www.vtk.org/Wiki/CMake/Examples#Finding_Packages" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/CMake/<wbr>Examples#Finding_Packages</a><br>
but that's tied to vtk.<br>
<br>
Best,<br>
peter<br>
<span class="im HOEnZb"><br>
On 09/06/2016 08:12 PM, Cotton Candy wrote:<br>
> Peter,<br>
> In XCode I have this list of "settings" that includes<br>
> "Other Linker Flags" that I have set to "-lmysqlclient -lpthread -lm -lz"<br>
> and<br>
> "Other C++ Flags" that I have set to "-L/Applications/MAMP/Library/<wbr>lib<br>
> -lmysqlclient -lpthread -lz"<br>
><br>
> Maybe these explain why things work when I build with XCode, but not with<br>
> CMake.<br>
><br>
><br>
</span><div class="HOEnZb"><div class="h5">> but when I run the make it always says it is ignoring these (e.g. "warning:<br>
> argument unused during compilation: '-L/Applications/MAMP/Library/<wbr>lib'").<br>
><br>
> Thanks again for you help.<br>
> Aaron<br>
><br>
><br>
><br>
><br>
><br>
> On Tue, Sep 6, 2016 at 2:20 PM, Peter Steinbach <<a href="mailto:steinbach@scionics.de">steinbach@scionics.de</a>><br>
> wrote:<br>
><br>
>> Aaron,<br>
>><br>
>> it's about the way that you compile your binary and link libmysqlclient<br>
>> into it. I guess (@all: please correct me if I am wrong) as I don't know<br>
>> how you use cmake to build your libraries/binaries, that you don't set the<br>
>> rpath of libmysqlclient inside your binary. Doing so will ensure that the<br>
>> absolute path of libmysqlclient is stored into your binary, so that the<br>
>> runtime environment can pick it up and use (keeping fingers crossed that<br>
>> the path is still valid). The alternative to doing so, is linking against<br>
>> the static version of libmysqlclient (which comes at a cost on another<br>
>> front as well).<br>
>><br>
>> Best,<br>
>> P<br>
>><br>
><br>
</div></div></blockquote></div><br></div>