No subject


Thu Oct 17 21:49:17 EDT 2013


My question was perhaps not clear. Compiling the library is not a problem,
but from what I understood from Matthew first answer ("implicit compile
flags [...] for imported tagets"), I was under the impression that I could
get MYPROJECT_STATIC automatically defined when linking another program
against a static version of my library (through its imported target).

I've looked the documentation of target_compile_definitions, but it seems
to be about compiling the library, not linking against its imported target.
Am I right?


2013/10/31 David Cole <dlrdave at aol.com>

> Microsoft believed in hidden by default for shared libraries.
>>
>
> Don't say things like this: people will never hide anything ever again...
> ;-)
>
> But seriously, making only those things public that are explicitly
> exported has some major benefits: for one, it minimizes the probability of
> clashes when combining multiple independent components.
>
> It really should be a software developer's rule of thumb / best practice
> to have the minimal set of symbols necessary be exported. Anything exported
> that does not need to be is a maintenance burden, a learning curve hurdle
> for newbies, and increases the likelihood of name clashes with other
> libraries: all bad things.
>
> So minimize your public APIs and your exports.
>
>
> 2 cents worth,
>
> D
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>

--047d7b5d474a78fd4f04ea3526ad
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div>Wow, this thread has gone wild...<br><br></=
div>To clarify my case:<br></div>The prototype of each functions I want to =
export is prefixed by a MYPROJECT_EXTERNAL preprocessor constant. With Visu=
al Studio, this constant is, by default, set to __declspec(dllimport). This=
 way, I can link against the shared version of this library without having =
to define anything.<br>
<br>When compiling this library as a shared library, I have to define a MYP=
ROJECT_EXPORT_SHARED constant, which will set MYPROJECT_EXTERNAL to __decls=
pec(dllimport).<br><br></div><div>But if I want to build/link against a sta=
tic version of this library, I need to pass a MYPROJECT_STATIC as a define =
in order to set MYPROJECT_EXTERNAL to nothing.<br>
<br></div><div>From what I&#39;ve read in your answers, it seems to be the =
way to go.<br></div><div><br></div><div>My question was perhaps not clear. =
Compiling the library is not a problem, but from what I understood from Mat=
thew first answer (&quot;implicit compile flags [...] for imported tagets&q=
uot;), I was under the impression that I could get MYPROJECT_STATIC automat=
ically defined when linking another program against a static version of my =
library (through its imported target).<br>
<br></div><div>I&#39;ve looked the documentation of target_compile_definiti=
ons, but it seems to be about compiling the library, not linking against it=
s imported target. Am I right?<br></div></div><div class=3D"gmail_extra">
<br><br><div class=3D"gmail_quote">2013/10/31 David Cole <span dir=3D"ltr">=
&lt;<a href=3D"mailto:dlrdave at aol.com" target=3D"_blank">dlrdave at aol.com</a=
>&gt;</span><br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex">
<div class=3D"im"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .=
8ex;border-left:1px #ccc solid;padding-left:1ex">
Microsoft believed in hidden by default for shared libraries.<br>
</blockquote>
<br></div>
Don&#39;t say things like this: people will never hide anything ever again.=
.. ;-)<br>
<br>
But seriously, making only those things public that are explicitly exported=
 has some major benefits: for one, it minimizes the probability of clashes =
when combining multiple independent components.<br>
<br>
It really should be a software developer&#39;s rule of thumb / best practic=
e to have the minimal set of symbols necessary be exported. Anything export=
ed that does not need to be is a maintenance burden, a learning curve hurdl=
e for newbies, and increases the likelihood of name clashes with other libr=
aries: all bad things.<br>

<br>
So minimize your public APIs and your exports.<br>
<br>
<br>
2 cents worth,<div class=3D"HOEnZb"><div class=3D"h5"><br>
D<br>
<br>
--<br>
<br>
Powered by <a href=3D"http://www.kitware.com" target=3D"_blank">www.kitware=
.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href=3D"http:/=
/www.cmake.org/Wiki/CMake_FAQ" target=3D"_blank">http://www.cmake.org/Wiki/=
<u></u>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more in=
formation on each offering, please visit:<br>
<br>
CMake Support: <a href=3D"http://cmake.org/cmake/help/support.html" target=
=3D"_blank">http://cmake.org/cmake/help/<u></u>support.html</a><br>
CMake Consulting: <a href=3D"http://cmake.org/cmake/help/consulting.html" t=
arget=3D"_blank">http://cmake.org/cmake/help/<u></u>consulting.html</a><br>
CMake Training Courses: <a href=3D"http://cmake.org/cmake/help/training.htm=
l" target=3D"_blank">http://cmake.org/cmake/help/<u></u>training.html</a><b=
r>
<br>
Visit other Kitware open-source projects at <a href=3D"http://www.kitware.c=
om/opensource/opensource.html" target=3D"_blank">http://www.kitware.com/<u>=
</u>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href=3D"http://www.cmake.org/mailman/listinfo/cmake" target=3D"_blank">h=
ttp://www.cmake.org/mailman/<u></u>listinfo/cmake</a><br>
</div></div></blockquote></div><br></div>

--047d7b5d474a78fd4f04ea3526ad--


More information about the CMake mailing list