<div dir="ltr"><div><div><div>Hi Franck,<br><br></div>I'd suggest going a little more robust by using both CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_SHARED_LIBRARY_SUFFIX to generate a function at configure time to resolve the correct filename.</div><div><br></div><div>For example, <a href="http://util.h.in">util.h.in</a>:<br></div></div><br><span style="font-family:monospace,monospace">#ifndef _UTIL_H_<br>#define _UTIL_H_<br><br>#include <stdio.h><br><br>static inline<br>void get_library_filename(char* filename, const char* libname)<br>{<br>  sprintf(filename, "@CMAKE_SHARED_LIBRARY_PREFIX@%s@CMAKE_SHARED_LIBRARY_SUFFIX@", libname);<br>}<br><br>#endif /* _UTIL_H_ */<br></span><br><div><br></div><div>Then your CMakeLists.txt:</div><div><br></div><div><span style="font-family:monospace,monospace">configure_file(<br>  ${CMAKE_CURRENT_SOURCE_DIR}/<a href="http://util.h.in">util.h.in</a><br>  ${CMAKE_CURRENT_BINARY_DIR}/util.h<br>  @ONLY<br>)<br>add_executable(foo main.c ${CMAKE_CURRENT_BINARY_DIR}/util.h)<br>target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})<br></span><br></div><div>And finally main.c:</div><div><br></div><div><span style="font-family:monospace,monospace">#include <stdio.h><br>#include <util.h><br><br>int main(int argc, char **argv)<br>{<br>  char filename[256];<br><br>  get_library_filename(filename, "foo");<br><br>  printf("Library foo uses file %s\n", filename);<br><br>  return 0;<br>}<br></span><br></div><div>This will give you "<span style="font-family:monospace,monospace">libfoo.so</span>" on Linux, "<span style="font-family:monospace,monospace">libfoo.dylib</span>" on Apple, and "<span style="font-family:monospace,monospace">foo.dll</span>" on Windows.</div><div><br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">----------<br>Chuck Atkins<br>Staff R&D Engineer, Scientific Computing<br>Kitware, Inc.<br><br></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Jan 9, 2018 at 10:04 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks !<br>
<br>
----- Mail original -----<br>
> De: "Konstantin Tokarev" <<a href="mailto:annulen@yandex.ru">annulen@yandex.ru</a>><br>
> À: "Franck Houssen" <<a href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>>, "CMake Mail List" <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>><br>
> Envoyé: Mardi 9 Janvier 2018 16:00:55<br>
> Objet: Re: [CMake] how to detect architecture ?<br>
<span class="">><br>
><br>
><br>
> 09.01.2018, 17:58, "Franck Houssen" <<a href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>>:<br>
> > Is there a way to detect architecture ?<br>
> ><br>
> > Seems there is nothing simple since these old threads :<br>
> > <a href="https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake/12024211#12024211" rel="noreferrer" target="_blank">https://stackoverflow.com/<wbr>questions/11944060/how-to-<wbr>detect-target-architecture-<wbr>using-cmake/12024211#12024211</a><br>
> > <a href="https://stackoverflow.com/questions/16796629/cmake-create-architecture-aware-makefile" rel="noreferrer" target="_blank">https://stackoverflow.com/<wbr>questions/16796629/cmake-<wbr>create-architecture-aware-<wbr>makefile</a><br>
> ><br>
> > Is there a solution now ?<br>
> ><br>
> > My need is quite simple: I have an executable who needs dlopen. To test it,<br>
> > I planned to write a bash script that would have done "./exe<br>
> > /path/to/lib.so" on linux (debian, ...) OR "./exe /path/to/lib.dylib" on<br>
> > osx. To replace correctly so/dylib in the bash script I need to know the<br>
> > architecture. Any idea how to do this ?<br>
><br>
> ${CMAKE_SHARED_LIBRARY_SUFFIX}<br>
><br>
<br>
</span>Oh man ! Didn't know this one : exactly what I was looking for<br>
<div class="HOEnZb"><div class="h5"><br>
> > Franck<br>
> > ,--<br>
> ><br>
> > Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
> ><br>
> > Please keep messages on-topic and check the CMake FAQ at:<br>
> > <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
> ><br>
> > Kitware offers various services to support the CMake community. For more<br>
> > information on each offering, please visit:<br>
> ><br>
> > CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
> > CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
> > CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
> ><br>
> > Visit other Kitware open-source projects at<br>
> > <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
> ><br>
> > Follow this link to subscribe/unsubscribe:<br>
> > <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
><br>
><br>
> --<br>
> Regards,<br>
> Konstantin<br>
><br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
</div></div></blockquote></div><br></div></div>