<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Hiya<div><br></div><div>Bit of newbie question here prompted by the fact that i just got the mail below from someone running OSX :-)</div><div><br></div><div>Im on a G4 running 10.4.11 and XCode 2.5</div><div><br></div><div>At the moment all Id ilke to do is write a Cocoa based app that uses GMP for the math, using the static library.</div><div><br></div><div>Ive read the mailings list and tried all the good things suggested but still come up with linking errors similar to those described below. </div><div>If I start with an empty Cocoa app with a single action I can declare </div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">mpz_t N;</span></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div>but the compiler balks when it hits<span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "></span></div><div><br></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">mpz_init (N);</span></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div>Have you got any suggestions please. Ive tried so many different ways of compiling the library and app Im going nuts.</div><div>I have no idea how to apply the suggestion below.</div><div><br></div><div>Rod</div><div><br></div><div><br></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><div><html>On 17/03/2008, at 8:35 AM, David Monniaux wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">If one attempts linking multi-module programs using GMP on MacOS X 10.5,<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">using Apple's modified gcc 4.0.1 with the -std=c99, one gets errors<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">about duplicate symbols such as __gmpz_abs. The reason is that, in this<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">mode, Apple's gcc applies C99 semantics for the 'inline' keyword.<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Accordingly, gmp.h tests whether this is the case (via the preprocessor<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">symbol __GNUC_STDC_INLINE_) and acts accordingly.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Problem: contrary to the "official" versions of gcc that have the same<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">behavior, Apple's gcc does not define __GNUC_STDC_INLINE__ in order to<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">signal that it enforces the new standard C behavior for 'inline' when<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">run in C99 mode.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This breaks linking certain programs such as APRON<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(<a href="http://apron.cri.ensmp.fr/library/">http://apron.cri.ensmp.fr/library/</a>).</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Proposed fix:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">* test whether we're on gcc or compilers claiming to be compatible with it</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">** test whether we're on Apple's gcc</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">* test whether we're on a non-gcc C99-compliant compiler</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">* do other special cases</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Your opinion?</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#ifdef __GNUC__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">/* Apple's cc applies C99 semantics in C99 mode but does not define</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>__GNUC_STDC_INLINE__ */</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#ifdef __APPLE_CC__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#if defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__<span class="Apple-converted-space"> </span></div> <blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">= 199901L</div> </blockquote><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE inline</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#else</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE<span class="Apple-converted-space"> </span>extern __inline__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#else /* __APPLE_CC__ */</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#ifdef __GNUC_STDC_INLINE__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE extern __inline__ __attribute__<span class="Apple-converted-space"> </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">((__gnu_inline__))</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#else</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE<span class="Apple-converted-space"> </span>extern __inline__</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_INLINE_PROTOTYPES<span class="Apple-converted-space"> </span>1</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#endif /* __APPLE_CC__ */</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#elif defined(__STDC__) && __STDC__ >= 199901L /* __GNUC__*/</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE inline</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>ANSI mode (__STDC__ is 1 in that mode).<span class="Apple-converted-space"> </span>Inlining only actually takes</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>place under -O.<span class="Apple-converted-space"> </span>Without -O "foo" seems to be emitted whether it's used</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>or not, which is wasteful.<span class="Apple-converted-space"> </span>"extern inline foo()" isn't useful, the</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>"extern" is apparently ignored, so foo is inlined if possible but also</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>emitted as a global, which causes multiple definition errors when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>building a shared libgmp.<span class="Apple-converted-space"> </span>*/</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#elif defined(__SCO_VERSION__)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-converted-space"> </span>&& ! defined (__GMP_EXTERN_INLINE)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#define __GMP_EXTERN_INLINE<span class="Apple-converted-space"> </span>static inline</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">#endif</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">gmp-discuss mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:gmp-discuss@swox.com">gmp-discuss@swox.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="https://gmplib.org/mailman/listinfo/gmp-discuss">https://gmplib.org/mailman/listinfo/gmp-discuss</a></div> </blockquote></div><br></div></body></html>