我正在使用不是由我創建的庫。代碼用VS2015編譯並按照使用VS2015運行。我想用MinGW GCC編譯器進行編譯,最終使它運行在一臺運行在Linux上並使用GCC編譯器的大型計算機上。該庫應該與VS,MinGW for Windows和GCC for Linux一起工作。 然而,當我嘗試編譯它的代碼:: Blocks的我收到以下錯誤信息:使用VS編譯代碼但不使用MinGW
||=== Build: all in Chrono (compiler: GNU GCC Compiler) ===| C:\Chrono\chrono_source\src\chrono\parallel\ChThreadsSync.h||In member function 'void ChSpinlock::Lock()':| C:\Chrono\chrono_source\src\chrono\parallel\ChThreadsSync.h|81|error: 'YieldProcessor' was not declared in this scope| C:\Chrono\chrono_source\src\chrono\parallel\ChThreadsSync.h|83|error: 'ReadWriteBarrier' was not declared in this scope| C:\Chrono\chrono_source\src\chrono\parallel\ChThreadsSync.h||In member function 'void ChSpinlock::Unlock()':| C:\Chrono\chrono_source\src\chrono\parallel\ChThreadsSync.h|88|error: 'ReadWriteBarrier' was not declared in this scope| src\chrono\CMakeFiles\ChronoEngine.dir\build.make|462|recipe for target 'src/chrono/CMakeFiles/ChronoEngine.dir/physics/ChMarker.cpp.obj' failed| CMakeFiles\Makefile2|1040|recipe for target 'src/chrono/CMakeFiles/ChronoEngine.dir/all' failed| C:\Chrono\Chrono_CodeBlocks\Makefile|159|recipe for target 'all' failed| ||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 4 second(s)) ===|
在錯誤表現在下面列出的部分代碼:
#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編譯器進行編譯?
這是「C++」而不是「C」。 'C'沒有課,所以請正確標記你的問題。 –
您不能使用任何未在Linux上的gcc編譯器中出現的僅Microsoft的Visual Studio/VC++功能。你必須堅持使用ANSI C++。 – duffymo
這些都是避免使用'pthreads.h'的解決方法。在Linux上,你可能會希望**使用pthreads。 –