代码用VS编译但不用MinGW编译

时间:2016-02-23 11:57:12

标签: c++ gcc mingw

我正在使用不是由我创建的库。该代码使用VS2015进行编译,并使用VS2015进行运行。我想用MinGW GCC编译器编译它,最终使它在一台运行在Linux上并使用GCC编译器的大型计算机上运行。该库应该与VS,MinGW for Windows和GCC for Linux一起使用。 但是,当我尝试在Code :: Blocks中编译它时,我收到以下错误消息:

  

|| === Build:所有在Chrono(编译器:GNU GCC编译器)=== |   C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h ||在成员函数' void ChSpinlock :: Lock()':   C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h | 81 | error:' YieldProcessor'未在此范围内声明|   C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h | 83 | error:' ReadWriteBarrier'未在此范围内声明|   C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h ||在成员函数' void ChSpinlock :: Unlock()':|   C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h | 88 | error:' ReadWriteBarrier'未在此范围内声明|   src \ chrono \ CMakeFiles \ ChronoEngine.dir \ build.make | 462 |目标配方&s; crc / chrono / CMakeFiles / ChronoEngine.dir / physics / ChMarker.cpp.obj'失败|   CMakeFiles \ Makefile2 | 1040 |目标配方&s; src / chrono / CMakeFiles / ChronoEngine.dir / all'失败|   C:\ Chrono \ Chrono_CodeBlocks \ Makefile | 159 |目标配方'全部'失败|   || ===构建失败:6个错误,0个警告(0分钟,4秒(秒))=== |

下面列出了显示错误的代码部分:

#define EBUSY 16
#pragma intrinsic(InterlockedExchange)
#pragma intrinsic(ReadWriteBarrier)

/// Class that wraps a spinlock, a very fast locking mutex
/// that should be used only for short wait periods.
/// This uses MSVC intrinsics to mimic a fast spinlock as
/// in pthreads.h, but without the need of including
/// the pthreads library for windows.
/// See http://locklessinc.com/articles/pthreads_on_windows/
class ChApi ChSpinlock {
  public:
ChSpinlock() { lock = 0; }
~ChSpinlock() {}
void Lock() {
    while (InterlockedExchange(&lock, EBUSY)) {
        /* Don't lock the bus whilst waiting */
        while (lock) {
            YieldProcessor();
            /* Compiler barrier.  Prevent caching of *l */
            ReadWriteBarrier();
        }
    }
}
void Unlock() {
    ReadWriteBarrier();
    lock = 0;
}

  private:
typedef long pseudo_pthread_spinlock_t;
pseudo_pthread_spinlock_t lock;
};

因此,正如我所理解的那样,有些代码可以让它在VisualStudio上运行。 我的问题是,如何使用MinGW编译器进行编译?

1 个答案:

答案 0 :(得分:0)

它看起来不像库问题,而是写在该文件中的代码。你需要删除任何MSVC特定的内容,例如#pragma intrinsic()

有关将代码移植到GCC的人员,请参阅here