<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — c and c++ project]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=764</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=764&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in c and c++ project.]]></description>
		<lastBuildDate>Thu, 15 Feb 2024 12:52:15 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4280#p4280</link>
			<description><![CDATA[<p>You only need to link to the standard C++ library if you or your external C/C++ code is using C++.&nbsp; If you&#039;re trying to link to a pure C library, there&#039;s no need to add the flag to link to the standard C++ library.&nbsp; The original post specifically asked about linking to C++, which is why I mentioned it.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 15 Feb 2024 12:52:15 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4280#p4280</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4279#p4279</link>
			<description><![CDATA[<p>Thank you for the overview.</p><p>I can appreciate the difficulties, although the example in this post was relatively simple.</p><p>When you say that there is a good chance that I’m not adding the standard C++ library flag for linking, what would that be?</p>]]></description>
			<author><![CDATA[null@example.com (david.jeong)]]></author>
			<pubDate>Thu, 15 Feb 2024 01:52:06 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4279#p4279</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4278#p4278</link>
			<description><![CDATA[<p>A C header file usually only declares prototypes for C procedures and provides constants.&nbsp; The availability of the procedures in a header file really depends on what specifically you&#039;re talking about.&nbsp; If you have an accompanying library that corresponds to the C file, then you would just need to create Fortran interfaces based on what the C header declares and link with the corresponding library.</p><p>If you&#039;re attempting to use functions in the C standard library that are mentioned in C header files, then you don&#039;t need to explicitly link to the library.&nbsp; The Fortran compiler will link to the C standard library regardless.</p><p>You only need to add the standard C++ library flag for linking if you&#039;re linking with the standard C++ library.&nbsp; There&#039;s a good chance you&#039;re not, though.</p><p>If you have the accompanying C source files for your header file, you can just add them to your project in Simply Fortran, and they should also be compiled.</p><p>To be clear, though, interfacing C routines isn&#039;t particularly simple.&nbsp; I&#039;m providing a very high level overview of what you need.&nbsp; It could get substantially more complicated quickly if you need to link multiple libraries (or you have to build a C library yourself first...).</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 14 Feb 2024 21:12:02 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4278#p4278</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4277#p4277</link>
			<description><![CDATA[<p>Are the interoperability procedures in this post the same if one only has a *.h file rather than *.c file?&nbsp; All I know about C language is that *.h is called a header file.&nbsp; </p><p>What I mean by the interoperability procedures is (1) to use iso_c_binding, (2) including the interface, and (3) adding -lstdc++ in the linker for compiler flags in the project options.</p><p>Thank you for any assistance you can provide.</p>]]></description>
			<author><![CDATA[null@example.com (david.jeong)]]></author>
			<pubDate>Tue, 13 Feb 2024 23:26:48 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4277#p4277</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3977#p3977</link>
			<description><![CDATA[<p>I&#039;m guessing that the output is in the internal <em>* Console *</em> tab.&nbsp; Is that correct?&nbsp; I&#039;m surprised it&#039;s working that way on Windows, but you can probably fix it by adding a carriage return as well:</p><div class="codebox"><pre><code>    printf(&quot;aaa \r\n&quot;);</code></pre></div><p>I&#039;m wondering, does the code work as expected in an External Console without the carriage return?</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 20 Sep 2022 12:18:10 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3977#p3977</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3970#p3970</link>
			<description><![CDATA[<p>In your FORTRAN with c code, I replaced timestwo with this</p><p>float timestwo(float x)<br />{<br />&nbsp; &nbsp; printf(&quot;aaa \n&quot;);<br />&nbsp; &nbsp; printf(&quot;%f \n&quot;, x);<br />&nbsp; &nbsp; printf(&quot;bbb\n&quot;);<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; return x * 2.0;<br />}</p><p>The output ignored the newlines and gave this</p><p>aaa 3.000000 bbb</p><p>Any thoughts?<br />K</p>]]></description>
			<author><![CDATA[null@example.com (kmutiny)]]></author>
			<pubDate>Thu, 15 Sep 2022 22:35:21 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3970#p3970</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3549#p3549</link>
			<description><![CDATA[<p>Thanks.<br />Anything more you can provide would be most helpful.</p>]]></description>
			<author><![CDATA[null@example.com (kmutiny)]]></author>
			<pubDate>Tue, 28 Jul 2020 16:04:36 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3549#p3549</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3547#p3547</link>
			<description><![CDATA[<p>I&#039;ll have to work up some more complex examples, but you&#039;ll want to look into using the <em>iso_c_binding</em> module, which allows interfacing Fortran with C (and, hence, a whole collection of C-compatible languages).&nbsp; For example, I can write a very simple Fortran program that calls a C floating-point routine:</p><div class="codebox"><pre><code>program main
use iso_c_binding
implicit none

    real::timesval

    interface
        function timestwo(x) bind(c)
        use iso_c_binding
        real(kind=c_float)::timestwo
        real(kind=c_float), value::x
        end function timestwo
    end interface

    print *, &quot;Times two via C&quot;

    write(*, &#039;(1X, A21)&#039;, advance=&#039;no&#039;) &quot;Enter a real number: &quot;
    read(*, *) timesval

    write(*, &#039;(1X, A43, F8.3, A4, F8.3)&#039;) &quot;The C language tells me that two times &quot;, &amp;
                                          real(timesval, kind=c_float), &amp;
                                          &quot; is &quot;, &amp;
                                          timestwo(timesval)

end program main</code></pre></div><p>You&#039;ll notice I&#039;ve written a Fortran interface defining a function, <em>timestwo</em> that is a C function (hence the <em>bind(c)</em> appearing in the function&#039;s definition.&nbsp; Also, I&#039;ve marked the passed argument <em>x</em> as <em>value</em> because Fortran always passes by reference, while C always passes by value.&nbsp; I can then create a C file that contains:</p><div class="codebox"><pre><code>float timestwo(float x)
{
    return x * 2.0;
}</code></pre></div><p>If I add both files to a Simply Fortran project, it will just work, and the output is what you&#039;d expect:</p><div class="codebox"><pre><code> Times two via C
 Enter a real number: 6.0
     The C language tells me that two times    6.000 is   12.000</code></pre></div><p>I&#039;ll have to find some more complicated examples to display.&nbsp; But the key is using the <em>iso_c_binding</em> module.&nbsp; Simply Fortran will just accept a C file added to a project, though, so there is no complication from a development environment perspective.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 27 Jul 2020 17:35:47 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3547#p3547</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3544#p3544</link>
			<description><![CDATA[<p>Do your mixed language projects have C/C++ calling Fortran functions and vice versa?<br />Is there any extra interoperability code that is needed?<br />Can you make a mixed language project available for us to look at?<br />Or direct us to a web source to learn from that is consistent with SF?</p>]]></description>
			<author><![CDATA[null@example.com (kmutiny)]]></author>
			<pubDate>Fri, 24 Jul 2020 17:55:54 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3544#p3544</guid>
		</item>
		<item>
			<title><![CDATA[Re: c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3539#p3539</link>
			<description><![CDATA[<p>Simply Fortran has reasonably good support for the C language (in terms of the File Outline and searching for procedure definitions) and somewhat basic support for C++. It also includes the C and C++ compiler on Windows and macOS.&nbsp; You can just add the C or C++ files to a project just like any Fortran file.&nbsp; When you build the project, it should have no problem with those files.&nbsp; </p><p>A project containing C++ files does need an explicit library linking command, though, because of our default linking step.&nbsp; In Project Options under Compiler flags, one would need to add:<br /></p><div class="codebox"><pre><code>-lstdc++</code></pre></div><p>to the Linker box to ensure that the C++ standard library is also linked.&nbsp; </p><p>There&#039;s really no additional steps.&nbsp; You can mix C and Fortran source in the same project (I do this regularly), and Simply Fortran will compile it all.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 14 Jul 2020 11:21:14 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3539#p3539</guid>
		</item>
		<item>
			<title><![CDATA[c and c++ project]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=3537#p3537</link>
			<description><![CDATA[<p>Can SF be used as a c and c++ ide?<br />If so, can you explain how?</p>]]></description>
			<author><![CDATA[null@example.com (kmutiny)]]></author>
			<pubDate>Mon, 13 Jul 2020 18:47:00 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=3537#p3537</guid>
		</item>
	</channel>
</rss>
