Search code examples
c++eigen

bench/BenchTimer.h (31) syntax error: 'volatile'


Could you help me with this flabbergasting error in Eigen? "bench/BenchTimer.h (31) syntax error: 'volatile'"

The offending code: bench/BenchTimer.h

static void escape(void *p) {
  asm volatile("" : : "g"(p) : "memory");
}

static void clobber() {
  asm volatile("" : : : "memory");
}

My code: tests.cpp

    #include <iostream>
    #include <bench/BenchTimer.h>

    int main() {
            Eigen::BenchTimer t;
            t.reset(); t.start();

            //TestEigenSolveSpeed();

            t.stop();
            std::cout << t.value()  << std::endl;

            return 0;
    }

CMakeLists.txt

    cmake_minimum_required(VERSION 3.11)

    set(LEVELING_NAME test-eigen)

    project(${LEVELING_NAME})

    add_executable(${LEVELING_NAME} tests.cpp )

    target_include_directories(${LEVELING_NAME} PUBLIC
            ${CMAKE_CURRENT_LIST_DIR}/deps/eigen-master 
    )

Folder structure:

    /
    |
    -- CMakeLists.txt
    -- tests.cpp
    -- deps
       |
       -- eigen-master

Created solution with: cmake . -DCMAKE_GENERATOR_PLATFORM=x64 -B build

In Windows, in VS2017

with newest repository version: master version 3.3.3

Here is the three files plus the repository in a zip for ease of reproduction: https://www.dropbox.com/s/avpfbabo4l9ti5h/test-eigen-error-volatile.zip?dl=0


Solution

  • As ggael mentioned, the solution is commenting the two offending code lines:

    static void escape(void *p) {
      //asm volatile("" : : "g"(p) : "memory");
    }
    
    static void clobber() {
      //asm volatile("" : : : "memory");
    }
    

    This "volatile" does not seem supported/accepted by MSVS2017

    It is however already fixed by ggael in the newest version of the repository :)