首页 文章

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

提问于
浏览
-3

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

|| === Build:all in 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 |错误:'YieldProcessor'未在此范围内声明C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h | 83 |错误:'ReadWriteBarrier'未在此范围内声明C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h ||在成员函数'void ChSpinlock :: Unlock()'中: C:\ Chrono \ chrono_source \ src \ chrono \ parallel \ ChThreadsSync.h | 88 |错误:'ReadWriteBarrier'未在此范围内声明src \ chrono \ CMakeFiles \ ChronoEngine.dir \ build.make | 462 |目标'src / chrono / CMakeFiles / ChronoEngine.dir / physics / ChMarker.cpp.obj'的配方失败CMakeFiles \ Makefile2 | 1040 |目标'src / chrono / CMakeFiles / ChronoEngine.dir / all的配方失败| C:\ Chrono \ Chrono_CodeBlocks \ Makefile | 159 |目标'all'的配方失败| || ===构建失败: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

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

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

相关问题