Unable to compile the program:

#include <stdio.h> #include <boost/thread/thread.hpp> #include <boost/interprocess/sync/named_semaphore.hpp> int main(int argc, char const *argv[]) { printf("Test start\n"); return 0; } 

I collect g ++ for MinGW, boost version 1_60, makefile

 BOOST_DIR = "d:\workspace\boost_1_60_0" BOOST_LIB_DIR = "d:\workspace\boost_1_60_0\stage\lib" BOOST_VERSION = 1_60 .PHONY: boost_semaphore boost_semaphore: boost_semaphore.cpp g++ boost_semaphore.cpp -I${BOOST_DIR} -m32 -march=i686 -std=c++11 -static-libstdc++ -o test.exe -L${BOOST_LIB_DIR} -lboost_system-mgw49-mt-${BOOST_VERSION} -lboost_thread-mgw49-mt-${BOOST_VERSION} -lboost_chrono-mgw49-mt-${BOOST_VERSION} 

When building displays errors like:

In file included from d: \ workspace \ boost_1_60_0 / boost / interprocess / errors.hpp: 41: 0, from d: \ workspace \ boost_1_60_0 / boost / interprocess / exceptions.hpp: 24, from d: \ workspace \ boost_1_60_0 / boost /interprocess/sync/named_semaphore.hpp:25, from boost_semaphore.cpp: 3: d: \ workspace \ boost_1_60_0 / boost / interprocess / detail / win32_api.hpp: 870: 116: warning: declaration of 'void * boost :: interprocess :: winapi :: CreateMutexA (boost :: inter process :: winapi :: interprocess_security_attributes *, int, const char *) 'with C "link" (dllimport) void * __stdcall CreateMutexA (interprocess_security_attributes *, int, const char *);

In file included from d: \ workspace \ boost_1_60_0 / boost / thread / win32 / thread_data.hpp: 11: 0, from d: \ workspace \ boost_1_60_0 / boost / thread / thread_only.hpp: 15, from d: \ workspace \ boost_1_60_0 /boost/thread/thread.hpp:12, from boost_semaphore.cpp: 2: d: \ workspace \ boost_1_60_0 / boost / thread / win32 / thread_primitives.hpp: 171: 55: warning: conflicts with previous declaration 'void * boost: : detail :: win32 :: CreateMutex A (boost :: detail :: win32 :: _ SECURITY_ATTRIBUTES *, int, const char *) '__declspec (dllimport) void * __stdcall CreateMutexA (_SECURITY_ATTRIBUTES *, int, char const *);

I understand it is a redefinition of functions, and with different extern "c" prefixes and without, I do not understand how to avoid this? I did not correctly boost or need to use other header files or special defains?

  • These are not errors, these are warnings. - ixSci
  • Apparently , incorrectly collected. - αλεχολυτ
  • one
    @alexolut, these warnings cannot be related to the build. Apparently this is an old and well-known problem. - ixSci
  • @ixSci, it’s just not necessary to collect for win, so there will be no warnings :) In general, of course, it’s surprising how long known bugs can live in fairly large projects. - αλεχολυτ

1 answer 1

When building a boost for windows , so that there are no disagreements in header files and similar warnings, I recommend adding define BOOST_USE_WINDOWS_H .

If you are collecting a boost with the bjam.exe utility, then add add define=BOOST_USE_WINDOWS_H to its parameters. If the build goes through make, use the -DBOOST_USE_WINDOWS_H for g ++.