Boost C++ Libraries: Ticket #5326: several g++ warnings found when compile boost::interprocess examples https://svn.boost.org/trac10/ticket/5326 <p> Hi, When I compiled the examples on boost_1_46_1/doc/html/interprocess/synchronization_mechanisms.html, in windows 7 g++ mingw 4.5.2 generated the executable with the following warnings(though the program run correctly). </p> <p> output of g++ mingw 4.5.2 in DevC++: Compiler: Default compiler Building Makefile: "C:\code\test\ipc2\dev\Makefile.win" Executing make... mingw32-make -f "C:\code\test\ipc2\dev\Makefile.win" all g++.exe -c ../ipc2.cpp -o ../ipc2.o -I"include" -I"F:/boost_1_46_1" -Wall -Wno-deprecated -DWIN32 -mthreads -march=i686 -fexceptions -std=gnu++0x -DNDEBUG -fexceptions -O2 </p> <p> In file included from F:/boost_1_46_1/boost/interprocess/errors.hpp:37:0, </p> <blockquote> <p> from F:/boost_1_46_1/boost/interprocess/exceptions.hpp:20, from F:/boost_1_46_1/boost/interprocess/shared_memory_object.hpp:17, from ../ipc2.cpp:1: </p> </blockquote> <p> F:/boost_1_46_1/boost/interprocess/detail/win32_api.hpp: In function 'bool boost::interprocess::winapi::get_wmi_class_attribute(std::wstring&amp;, const wchar_t*, const wchar_t*)': F:/boost_1_46_1/boost/interprocess/detail/win32_api.hpp:1472:21: warning: unused variable 'co_initialize_end' </p> <p> In file included from F:/boost_1_46_1/boost/date_time/microsec_time_clock.hpp:23:0, </p> <blockquote> <p> from F:/boost_1_46_1/boost/date_time/posix_time/posix_time_types.hpp:11, </p> </blockquote> <blockquote> <p> from F:/boost_1_46_1/boost/interprocess/detail/posix_time_types_wrk.hpp:23, from F:/boost_1_46_1/boost/interprocess/sync/scoped_lock.hpp:31, from ../ipc2.cpp:3: </p> </blockquote> <p> F:/boost_1_46_1/boost/date_time/filetime_functions.hpp: At global scope: F:/boost_1_46_1/boost/date_time/filetime_functions.hpp:57:90: warning: declaration of 'void boost::date_time::winapi::<a class="missing wiki">GetSystemTimeAsFileTime</a>(boost::date_time::winapi::FILETIME*)' with C language linkage F:/boost_1_46_1/boost/interprocess/detail/win32_api.hpp:798:49: warning: conflicts with previous declaration 'void boost::interprocess::winapi::<a class="missing wiki">GetSystemTimeAsFileTime</a>(boost::interprocess::winapi::interprocess_filetime*)' F:/boost_1_46_1/boost/date_time/filetime_functions.hpp:58:122: warning: declaration of 'int boost::date_time::winapi::<a class="missing wiki">FileTimeToLocalFileTime</a>(const boost::date_time::winapi::FILETIME*, boost::date_time::winapi::FILETIME*)' with C language linkage F:/boost_1_46_1/boost/interprocess/detail/win32_api.hpp:799:49: warning: conflicts with previous declaration 'int boost::interprocess::winapi::<a class="missing wiki">FileTimeToLocalFileTime</a>(const boost::interprocess::winapi::interprocess_filetime*, const boost::interprocess::winapi::interprocess_filetime*)' </p> <p> ../ipc2.cpp: In function 'int main()': ../ipc2.cpp:18:10: warning: unused variable 'remover' </p> <p> g++.exe ../ipc2.o -o "ipc2.exe" -L"lib" -L"F:/boost_1_46_1/stage/lib" -s -lole32 -loleaut32 -lboost_date_time-mgw45-mt-1_46_1 -s </p> <p> Execution terminated </p> <p> source file: #include &lt;boost/interprocess/shared_memory_object.hpp&gt; #include &lt;boost/interprocess/mapped_region.hpp&gt; #include &lt;boost/interprocess/sync/scoped_lock.hpp&gt; #include "doc_anonymous_mutex_shared_data.hpp" #include &lt;iostream&gt; #include &lt;cstdio&gt; </p> <p> using namespace boost::interprocess; </p> <p> int main () { </p> <blockquote> <p> try { </p> <blockquote> <p> <em>Remove shared memory on destruction struct shm_remove { </em></p> <blockquote> <p> ~shm_remove(){ shared_memory_object::remove("<a class="missing wiki">MySharedMemory</a>"); } </p> </blockquote> <p> } remover; </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>Open the shared memory object. shared_memory_object shm </em></p> <blockquote> <p> (open_only <em>only create ,"<a class="missing wiki">MySharedMemory</a>" </em>name ,read_write <em>read-write mode ); </em></p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>Map the whole shared memory in this process mapped_region region </em></p> <blockquote> <p> (shm <em>What to map ,read_write </em>Map it as read-write ); </p> </blockquote> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>Get the address of the mapped region void * addr = region.get_address(); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>Construct the shared structure in memory shared_memory_log * data = static_cast&lt;shared_memory_log*&gt;(addr); </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em>Write some logs for(int i = 0; i &lt; 100; ++i){ </em></p> <blockquote> <p> <em>Lock the mutex scoped_lock&lt;interprocess_mutex&gt; lock(data-&gt;mutex); </em>std::sprintf(data-&gt;items[(data-&gt;current_line++) % shared_memory_log::<a class="missing wiki">NumItems</a>] </p> <blockquote> <p> <em> ,"%s_%d", "process_a", i); </em></p> </blockquote> </blockquote> <p> printf("%s\n",data-&gt;items[i]); </p> <blockquote> <p> if(i == (shared_memory_log::<a class="missing wiki">NumItems</a>-1)) </p> <blockquote> <p> data-&gt;end_b = true; </p> </blockquote> <p> <em>Mutex is released here </em></p> </blockquote> </blockquote> <p> } </p> </blockquote> <blockquote> <blockquote> <p> <em>Wait until the other process ends while(1){ </em></p> <blockquote> <p> scoped_lock&lt;interprocess_mutex&gt; lock(data-&gt;mutex); if(data-&gt;end_a) </p> <blockquote> <p> break; </p> </blockquote> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> catch(interprocess_exception &amp;ex) { </p> <blockquote> <p> std::cout &lt;&lt; "ipc exception caught:" &lt;&lt; ex.what() &lt;&lt; std::endl; return 1; </p> </blockquote> <p> } return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5326 Trac 1.4.3 Ion Gaztañaga Fri, 01 Apr 2011 21:54:55 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5326#comment:1 https://svn.boost.org/trac10/ticket/5326#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> Fixed co_initialize_end warning in Boost 1.47. The other warnings can't be fixed without moving windows predeclarations to a common place for Boost.Interprocess and Boost.<a class="missing wiki">DateTime</a>. </p> Ticket anonymous Fri, 21 Oct 2011 03:48:51 GMT <link>https://svn.boost.org/trac10/ticket/5326#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5326#comment:2</guid> <description> <p> I found this report via Google as I am experiencing the same issue. </p> <p> Is it possible to declare the variables with the <span class="underline">attribute</span> ((unused)) for GCC / MinGW ? </p> </description> <category>Ticket</category> </item> </channel> </rss>